The unix command test allows you to do that, among other things
Print YES or NO depending on a existance of a file[]
test -e Filename && echo 'YES' || echo 'NO'
Why i would need to do that?[]
In my case, i tried to make a file list in a text file and check some file attributes with a perl script for all files listed. The problem is, that the file list had lots of environment variables, (i.e. $HOME/dump/data.csv), and perl was not able to determine file existance with that kind of name.
I had 2 choices. To regexp the filename to expand things like $HOME to $ENV{"HOME"}, or use a unix command and capture its output.
The latter seemed simpler and less error-prone to me.
In my case, i had to check for file existance and file size > 0, so i used test with the -s parameter instead of -e.
See also[]
test man page (man test
)