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 ... 

from bash manual

nullglob

if set, bash allows filename patterns match no files expand null string, rather themselves.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -