Consider this simple loop:
for f in *.{text,txt}; do echo $f; done
I want to send ONLY valid file names. Using the $ f variable in a script all works fine if there are no files of this extension. In the case of an empty set, $ f is set to * .text and the above echos lines:
*.text *.txt
instead of not repeating anything. This creates an error if you try to use $ f for everything that expects the actual file name, and instead gets *.
If there are files matching a wildcard, so this is not an empty set, everything works as we would like. eg.
123.text 456.txt 789.txt
How can I do this without errors and without the seemingly excessive complexity of the first line corresponding to $ f for an asterisk?
source share