I have to process multiple files that I dont have the entire name for. I am running an if statement using a wildcard. for example...
if [ "ESGSN_*.SMS.EDR" ]; then
echo "There are files to process in this run"
for F in ESGSN_*.SMS.EDR; do
gzip < "$F" > "$F.gz"
done
fi
If there are multiple files or a single file this will work and zip them. But if there are no files it will still run the zip rather than just end. I was wondering if there is any way to get it to complete and move on.
I have tried using the operators "-f" and "-a" within the brackets just before the filename, but those will error out with: "binary operator expected"
for some reason the asterisk in the filename is not showing down below in the message. So the file name is "ESGSN_"*".SMS.EDR" where the double quotes is the asterisk.
*
there won't work since it is quoted""
. Globs don't expand when quoted. – Valentin Bajrami Jan 10 '19 at 21:14if [[ -f *.foo ]]; then echo foo; else echo bar; fi
works properly for me. Un quote the glob and you'll be fine. – DopeGhoti Jan 10 '19 at 21:17for f in ...
since there's only one file? – ilkkachu Jan 10 '19 at 22:39[[ -f *.foo ]]
tests to see if there's a file literally called*.foo
. It doesn't work to finda.foo
orb.foo
. – ilkkachu Jan 11 '19 at 11:29touch test.foo, [[ -f *.foo ]] && echo yep
. – DopeGhoti Jan 11 '19 at 15:31