1

How can the following be changed example so that it does glob expansion after loop variable substitution?

for i in a b c
    do echo $i/*.txt
done

UPDATE: This normally does work, however set -f had been done earlier in the script I'm looking at.

1
  • 2
    How does it "not work" at the moment?
    – choroba
    Commented Dec 2, 2014 at 17:09

1 Answer 1

1

If you're writing bash code, judicious use of "set -f" to turn off globbing, and "set +f" to turn globbing on might do what you want:

#!/bin/bash

for i in a b c
do
    set -f
    Z=$i/*.txt
    echo $Z
    set +f
    echo
    echo "Does it expand?"
    echo $Z
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .