How would you go about telling whether files of a specific extension are present in a directory, with bash?
Something like
if [ -e *.flac ]; then
echo true;
fi
How would you go about telling whether files of a specific extension are present in a directory, with bash?
Something like
if [ -e *.flac ]; then
echo true;
fi
Here is a solution using no external commands (i.e. no
ls
), but a shell function instead. Tested in bash:The function
have_any
uses$#
to count its arguments, and[ $# -gt 0 ]
then tests whether there is at least one argument. The use of./*.flac
instead of just*.flac
in the call tohave_any
is to avoid problems caused by files with names like--help
.