bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: for ... in ... do ignores escape characters


From: pk
Subject: Re: for ... in ... do ignores escape characters
Date: Fri, 18 Apr 2008 14:21:11 +0200

On Friday 18 April 2008 14:02, Dave Rutherford wrote:

> Quotes or escapes in the output of the `` are input to the shell rather
> than shell syntax, so won't be interpreted.  You just need to quote more.
> 
> $ foo () { echo sony; echo apple; echo hewlett packard; }
> 
> Now note the difference between:
> 
> $ for w in "`foo`"; do echo $w; done
> sony apple hewlett packard

This assigns 

"sony
apple
hewlett packard"

as a single value to $w. Since $w is not quoted in the echo statement,
format is lost. The for loop is executed only once.

> $ for w in `foo`; do echo "$w"; done
> sony
> apple
> hewlett
> packard

This assigns "sony", "apple", "hewlett", and "packard" in turn to $w. $w is
quoted in the echo statement (which does not change anything in this
case, since the values do not contain spaces).

> $ for w in "`foo`"; do echo "$w"; done
> sony
> apple
> hewlett packard

This assigns

"sony
apple
hewlett packard"

as a single value to $w, and format is preserved because $w is quoted in the
echo statement. Note that the for loop is executed only once. This
is not what the OP wanted.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]