That's not a good method for testing the existence of a file within a script. That's what the bash (and, waaaaaaaay before bash, the Bourne shell) test function is for.there is also the 'whereis' command that is a lot less complicated:
$>whereis startx
bash: /usr/X11/startx
if the file did not exist it would be like:
$>whereis foo
bash: no such file or directory
ETA: I was in a hurry when I wrote the above. Now I want to expand on WHY it's not a good method.
The whereis command is intended to "locate the binary, source, and manual page files for a command," according to its man page. It's basically searching the file system, whereas the bash test command is told where to look, and then just has to see if a specific file is there or not. Also, my output for whereis looks like this, using a file [which DEFINITELY exists] from argedion's project:
Code:
$ whereis fantasy_1.jpg
fantasy_1:
$ whereis fantasy_1
fantasy_1:
and then a program (backgammon) that also exists:
Code:
$ whereis gnubg
gnubg: /usr/lib/gnubg /usr/games/gnubg /usr/share/gnubg /usr/share/man/man6/gnubg.6.gz
So, for one thing, when it fails, it doesn't give a consistent output that could be used in a program. But the bigger issue--and the WORST issue--is that it fails even though a file exists! In my example, it's a JPEG, but the point is that whereis is used to "locate the binary, source, and manual page files for a command," not just any random file type.