Prevent globbing after variable substitution Prevent globbing after variable substitution shell shell

Prevent globbing after variable substitution


As an alternative to switching between set -f and set +f you could perhaps just apply a single set -f to a subshell since the environment of the parent shell would not by affected by this at all:

(set -ffor file in $(cat files); do   command1 < "$file"   echo "$file"done)# or evensh -f -c '   for file in $(cat files); do      command1 < "$file"      echo "$file"   done'


You can turn off globbing with set -f, then turn it back on later in the script with set +f.


Use while read instead.

cat files | while read file; do    command1 < "$file"    echo "$file"done