You need to be careful which flag you enter in your if , and how it relates to the desired result.
If you want to check only ordinary files , and not other types of records in the file system, you need to change the code skeleton to:
if [ -f file ]; then echo true; fi
Using -f limits if regular files, while -e is more expansive and matches all types of entries in the file system. Of course, there are other options, such as -d for directories, etc. See http://tldp.org/LDP/abs/html/fto.html for a good listing.
As @msw pointed out, test (i.e. [ ) will suffocate if you try to submit more than one argument. This can happen in your case if glob for *.flac returned more than one file. In this case, try wrapping the if test in a loop, for example:
for file in ./*.pdf do if [ -f "${file}" ]; then echo 'true'; break fi done
That way, you break in the first instance of the file extension you want, and you can continue to work with the rest of the script.
dtlussier 04 Oct 2018-10-10 15:46
source share