Simple Find file Script.....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple Find file Script.....
# 1  
Old 01-30-2009
Simple Find file Script.....

Im trying to make a very simple find the first file with the .zip extension in a specific folder and open that file.

The folder path and file name will vary every-time and it may contain spaces. If I try to look

For this example the folder directory is /Users/username/Desktop/testfolder/abc def/ and the file is firstfile.zip.

If I manually enter the file destination it does

Code:
file=`find ~/Desktop/testfolder/abc\ def -name '*.zip' | head -1`
echo $file

It finds the file.
/Users/user/Desktop/testfolder/abc def/firstfile.zip

but if I try to use a Variable for the path it fails.
Code:
downdir='~/Desktop/testfolder/abc\ def'
file=`find "$downdir" -name '*.zip' | head -1`
echo $file

It gives me an error
find: ~/Desktop/testfolder/abc\ def: No such file or directory

I tried to use single quotas and double quotas and no quotas but can't get this to go. Any help would be appreciated.
# 2  
Old 01-30-2009
double quotes -
Code:
downdir="~/Desktop/testfolder/abc\ def"

# 3  
Old 01-30-2009
I tried it but still have the same issue using double quotas.
find: ~/Desktop/testfolder/abc\ def: No such file or directory

Last edited by elbombillo; 01-30-2009 at 08:02 PM..
# 4  
Old 01-30-2009
The tilde has to be evaluate by the shell... much like a globbing char would be.

So you could force a layer of evalution.

For example
Code:
eval downdir="~/Desktop/testfolder/abc\ def"

Just a long as there's no variable involved in downdir... if there is, you have to VERY careful since a extra round of evaluation is being done (consider variables passed in with backticks or $() depending on shell).
# 5  
Old 01-30-2009
Thanks that worked.
# 6  
Old 01-31-2009
Quote:
Originally Posted by cjcox
Code:
eval downdir="~/Desktop/testfolder/abc\ def"


All you need is:

Code:
downdir=~/Desktop/testfolder/abc\ def

# 7  
Old 02-02-2009
Thanks cfajohnson.. you are correct.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

HELP simple script to find e-mail address on a file

Hello guys, im new to to unix/linux i have a text file like this: person1@test.com iisiiasasas person2@test.com 123w2 3233 sajsja person3@test.com jsajjsa sajsjasaj person4@test.com I want to extract only e-mail address and get rid of all other stuff, i want an output like this ... (4 Replies)
Discussion started by: RazorMX
4 Replies

2. UNIX for Dummies Questions & Answers

Help with simple script to find PID of process

Hi everyone. I've been reading around and am a little bit overwhelmed, hoping to find a kind soul out there to hold my hand through writing my first script. This need has emerged at work and I haven't much experience writing shell scripts, but this is a problem we have with a production environment... (13 Replies)
Discussion started by: thirdcoaster
13 Replies

3. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

4. Shell Programming and Scripting

Simple script to find common strings in two files

Hi , I want to write a simple script. I have two files file1: BCSpeciality Backend CB CBAPQualDisp CBCimsVFTRCK CBDSNQualDisp CBDefault CBDisney CBFaxMCGen CBMCGeneral CBMCQualDisp file2: CSpeciality Backend (8 Replies)
Discussion started by: ramky79
8 Replies

5. Shell Programming and Scripting

Simple shell script to find and print data

Hi, I have a log file containing data on emails sent. Looks a bit like this for one email: Content-Type: text/plain; charset="UTF-8" Date: 12 Jun 2008 14:04:59 +0100 From: from@email.com Subject: xcf4564xzcv To: recip@email.co.uk Size = 364 Jun 12 14:04 smtp_234sldfh.tmp I need to... (5 Replies)
Discussion started by: terry2009
5 Replies

6. Shell Programming and Scripting

simple script detect to find OS version/flavour

Hi, A newbie question. Following script gives no output. =============================== root@srv # cat /etc/redhat-release | awk {'print $1}' Red root@srv # cat 123.sh if (( `cat /etc/redhat-release | awk {'print $1}'` != CentOS )); then { echo "System runs on Redhat Linux. ... (13 Replies)
Discussion started by: fed.linuxgossip
13 Replies

7. Shell Programming and Scripting

Simple file checking script

Hi, I have a really, what I hope is, simple question. I'm looking for a simple way to see whether a file exists or not and then perform an action based on whether it exists or not. An example of what I tried is as follows: if then { echo "File mysql exists" ... (1 Reply)
Discussion started by: _Spare_Ribs_
1 Replies

8. Shell Programming and Scripting

Script to look for data in a file (not that simple) ...

I'm looking for a script or program that would allow me to pass a pattern to it and give me locations on where text appears in a file. I wish it was that straight forward (I would use egrep or something) Say I have the word in my text file "SUDAN" but my user does a search for "SUDANESE". Grep... (6 Replies)
Discussion started by: gseyforth
6 Replies

9. Shell Programming and Scripting

simple script to find the number of "tab"s...but,...

------------------------------ $x=" hi"; $tabspace=0; while ($x =~ /\t/g ) { $tabspace++; } print $tabspace; --------------------------------- 1.)when i tried it without "g" ($x = ~/\t/ )... when i run the script it utilizes around 95% cpu and system hangs and i did "End process"... (0 Replies)
Discussion started by: sekar sundaram
0 Replies

10. UNIX for Dummies Questions & Answers

Is a simple one command to find a file?

Hi All, I have did a search in the whole forum about Find, but get too many results, so I hope my message not annoying anyone. How do I do a find for a specific file in the whole machine? I am hoping for something like this. find . -name thanks (11 Replies)
Discussion started by: E-Quality
11 Replies
Login or Register to Ask a Question