Bash for loop and glob expansion -
this question has answer here:
consider following bash code:
f in /tmp/*.dat; echo ${f}; done
when run , there no *.dat
file in /tmp
output is:
/tmp/*.dat
which not want. however, when there such file, print out correct one
/tmp/foo.dat
how can force loop return 'nothing' when there no such file in directory. find
-command not option, sorry :/ have solution without testing, if *.dat
file or not. solutions far?
this should work:
shopt -s nullglob ...
nullglob
if set, bash allows filename patterns match no files expand null string, rather themselves.
Comments
Post a Comment