1

When pattern match this code work as intended:

mkdir -p mytestdir001
for f in "mytestdir???"; do
  echo $f
done

but when I replace wildcard so no item will be matched the for loop returns the wildcard.

Is there a way to prevent this other than checking in the loop if f variable is equal to initial wildcard ?

rsk82
  • 26,257
  • 48
  • 141
  • 229

1 Answers1

2

Set the nullglob option.

$ shopt -s nullglob
$ for f in *notfound ; do echo "$f" ; done
$
Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325