Computing.Net > Forums > Unix > test if file exists

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

test if file exists

Reply to Message Icon

Name: hernandez
Date: January 13, 2003 at 04:51:11 Pacific
OS: w98se
CPU/Ram: 128
Comment:

I've written some script that checks to see if a file exists but it's not working properly. I'm in korn shell.

if [ -e $filename ]
then
file_menu #call the function file_menu
else
echo data file does not exist
fi

i've tried this with dummy filenames and no matter what name i enter, it calls the function. it seems to ignore that the file doesn't exist.

what am i doing wrong?



Sponsored Link
Ads by Google

Response Number 1
Name: cdac
Date: January 13, 2003 at 05:59:02 Pacific
Reply:

The code looks fine to me .

But try using switch -s. ( More helpful as is checks for the file size as well ).

regards


0

Response Number 2
Name: James Boothe
Date: January 13, 2003 at 06:40:07 Pacific
Reply:

The -e is not valid on HP-UX:

-f does regular file exist?
-x does executable file exist?
-r does readable file exist?
-w does writable file exist?
-s does regular file gtr than size 0 exist?


0

Response Number 3
Name: hernandez
Date: January 13, 2003 at 07:36:53 Pacific
Reply:

thanks to both of you

it's sorted now


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Unix training cursor positioning ??



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: test if file exists

check file existence on remote serv www.computing.net/answers/unix/check-file-existence-on-remote-serv/7212.html

How to determine file exist or not? www.computing.net/answers/unix/how-to-determine-file-exist-or-not/3976.html

Finding if a file exists www.computing.net/answers/unix/finding-if-a-file-exists/2409.html