![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Checking for existence of a flat file in UNIX ! | Ariean | Shell Programming and Scripting | 4 | 04-25-2008 11:58 AM |
| checking for existence of table in oracle | kjs | SUN Solaris | 0 | 10-19-2007 12:21 AM |
| checking file existence | DILEEP410 | Shell Programming and Scripting | 3 | 01-24-2007 08:43 AM |
| File existence problem | anormal | UNIX for Dummies Questions & Answers | 2 | 05-15-2006 09:54 AM |
| File existence | mpang_ | Shell Programming and Scripting | 2 | 03-27-2006 08:27 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Checking the existence of a file..
Hi,
I am trying to check for the existence of a file using the 'test' and the file existence options. When trying to check for a file with a space in between e.g 'Team List', it gives the following error. learn1: line 3: test: `Team: binary operator expected I am pasting my code below as well: echo "Please enter a file name" read fname if test -f $fname then echo "$fname exists" else echo "$fname doesnot exist" fi Can someone help me with this... Regards, Indra |
| Forum Sponsor | ||
|
|
|
|||
|
solfreak is on the money with this one.
If you consider that the test command is looking for a single argument, and then you provide it with a list, then it will only test the first item in that list. So, I created a test script named "test.ksh". Here it is: Code:
#! /usr/bin/ksh
echo "enter a file name: \c"
read filename
if test -f "${filename}"; then
echo "Success: ${filename}"
else
echo "Failure: ${filename}"
fi
Code:
»ls one two.txt test.ksh »test.ksh enter a file name: one two.txt Success: one two.txt Code:
#! /usr/bin/ksh
echo "enter a file name: \c"
read filename
if test -f ${filename}; then
echo "Success: ${filename}"
else
echo "Failure: ${filename}"
fi
Code:
»test.ksh enter a file name: one two.txt Failure: one two.txt hth, gabe |