Is there a way to use a Filename Expansion within a test
expression, more specifically, a bash conditional expression?
For example:
[[ -f foo* ]] && echo 'found it!' || echo 'nope!';
... will output "nope!" either if the foobar
file exists on the current directory or not.
And adding a var
like...
bar=foo*
[[ -f `echo $bar` ]] && echo 'found it!' || echo 'nope!';
... will output "found it!" if the foobar
file exists, but only if the echo $bar
expansion returned only one file.
find
command. – PersianGulf Aug 13 '20 at 22:31-f foo*
be? Should it be true if all names that matchesfoo*
are regular files, or should it be true if some of the names matchingfoo*
are regular files? Note that it would be easier to define this for-e foo*
, which is not what you are using. – Kusalananda Aug 14 '20 at 05:39