I'm experimenting with while read
syntax and there is a thing I don't understand.
The most basic scenario which reproduces the problem is the following: a bash script a.sh
calls another script b.sh
and displays the lines echoed by it:
a.sh
#!/bin/bash
while read line; do echo "<<$line>>" done <<<
./b.sh
b.sh
#!/bin/bash
echo "Hello" echo "World"
Running b.sh
gives as expected:
Hello
World
On the other hand, when I run a.sh
, the output is:
<<Hello World>>
while I expect it to be:
<<Hello>>
<<World>>
What am I doing wrong?
""
quotes around"`./b.sh`"
and see what happens. – jw013 Oct 25 '14 at 00:35a.sh
to be surprised, just runecho \
./b.sh``. Then tryIFS=' '; echo \
./b.sh`` – jimmij Oct 25 '14 at 00:48./b.sh | while read ... done
works too. Would you like writing an answer, explaining why the code in my question doesn't work, while two other alternatives do? – Arseni Mourzenko Oct 25 '14 at 00:50./b.sh | ...
example does not use any expansions so doesn't have the quoting problem. I could have sworn there was already a question like this but I can't find one at the moment. – jw013 Oct 25 '14 at 00:56