Results 1 to 4 of 4
Hi ALL,
Can u help me out in solving this problem in bash script
My current working directory is ancy/sample
there are two file
ancy.sh ancy.txt
In ancy.sh script i ...
- 07-20-2006 #1Just Joined!
- Join Date
- Jul 2006
- Posts
- 25
To find file exists in current working directory bash script
Hi ALL,
Can u help me out in solving this problem in bash script
My current working directory is ancy/sample
there are two file
ancy.sh ancy.txt
In ancy.sh script i need to check whether ancy.txt is available
I need to check whether the file exists in current working directory
ancy,txt is stored in a variable called filename
and i need to check whether its a readble file
Help me out in this
- 07-20-2006 #2Linux User
- Join Date
- Jun 2006
- Posts
- 311
Hi ancy,
In your script, to see whether the file exits, you use
To see whether a file is readable you use -r option like the way you can use -f for file existence check.if [ ! -f "$filename" ]
then
echo "$filename does not exists in the current directory"
else
echo "$filename does exists in the current directory"
fi
Read the following website to know the very basics of Bash scripting : -
http://www.phptr.com/articles/articl...&seqNum=4&rl=1
With Regards,
Thinker
- 07-21-2006 #3Just Joined!
- Join Date
- Jul 2006
- Posts
- 25
Hi,
I executed the above statemnet
but it shows an compilation error
if[: not found]
I need to check whether the file exists in current working directory using unix bash scripting
- 07-21-2006 #4
hi ancy !!!
there must be a space between 'if' and '['
Originally Posted by ancy
if [ ! -f "$filename" ]
take care of spaces....
<=== { casper } ===>It is amazing what you can accomplish if you do not care who gets the credit.
New Users: Read This First


Reply With Quote
