[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Double quotes do not work in command substitution?
From: |
neitsch+bug-bash |
Subject: |
RE: Double quotes do not work in command substitution? |
Date: |
Tue, 3 Jul 2007 09:09:04 -0600 |
Yes, that's expected. If a command substitution undergoes word splitting, the
output will be split on whitespace. If it doesn't (you use the "$(...)" form,
with quotes around), the output forms a single word, which will result in 'a b
c' as the single value of $k.
This will do what you want:
$ eval "for k in $(echo \"a b\" c); do echo \$k; done"
a b
c
First the command substitution is performed inside the double quoted string,
resulting in
eval 'for k in "a b" c; do echo $k; done'
being executed. Running scripts with 'set -xv' is helpful in figuring out this
sort of thing.