shell - for loop splits double quoted word into two words if there is a space in between -


the following command works expected.

$ in "foo bar" "baz qux"; echo $i; done foo bar baz qux 

i expecting output of following commands same. isn't.

$ list='"foo bar" "baz qux"'; in $list; echo $i; done "foo bar" "baz qux" 

what can when iterate on $list, iterate twice, once "foo bar" , once more "baz qux".

please provide answers work on posix shells. going use concepts learnt answer in shell script.

i suggest reading here document instead:

list="foo bar baz qux"  while read -r i;     # quote parameter expansions, in case     # starts or ends whitespace, or contains multiple runs     # or whitespace, or pattern metacharacters * or ?     echo "$i" done <<eof $list eof 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -