• Coding
  • Unix shell script: using sed and bash

Here's a simple script in bash:
foo="one two three"
for i in $foo; do
    echo $i;
done
The script executes as expected:
$ ./script.ksh
one
two
three
However if I replace the loop with this:
foo="one two three"
for i in $(sed -e 's/bar/$foo/' <(echo $1));
do
    echo $i
done
I execute it and this is what I get:
$ ./script.ksh bar
$foo
How can I make for expand the result of the sed command into a variable?
i'm not sure if this is what you want.
foo="one two three";
for i in $(echo $1 | sed -e "s/bar/$foo/"); do
    echo $i;
done
Yes this is what I wanted. I did not realize it was a quoting issue at first.

My first solution was not as pleasant, I came up with something like this:
foo="one two three";
for i in $(eval echo $(echo $1 | sed -e 's/bar/$foo/')); do
    echo $i;
done