![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| 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 02:58 PM |
| checking for existence of table in oracle | kjs | SUN Solaris | 0 | 10-19-2007 03:21 AM |
| checking file existence | DILEEP410 | Shell Programming and Scripting | 3 | 01-24-2007 12:43 PM |
| File existence problem | anormal | UNIX for Dummies Questions & Answers | 2 | 05-15-2006 12:54 PM |
| File existence | mpang_ | Shell Programming and Scripting | 2 | 03-27-2006 11:27 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | 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 |
|
||||
|
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 |
|
||||
|
Thanks everyone for helping me with this.
Thanks & regards, Indra |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|