Yes, but the last instruction is doing "f=$s"
About the sub-shelling stuff... in this case that is not why 'f' is blank
The 'while' is executed in the same shell
[mar...@amartir01 ~]$ echo $$ ; echo -n "foo|bar" | awk
'BEGIN{RS="|"}{ print $1 }' | while read s; do f=$s ; echo "f=$f" ;
echo $$ ; done ; echo "f=$f"
5997 <== Same shell
f=foo
5997 <== Same shell
f=bar
5997 <== Same shell
f=
If it was the reason, it could be fixed by exporting 'f' before the pipe
[mar...@amartir01 ~]$ export f="" ; echo -n "foo|bar" | awk
'BEGIN{RS="|"}{ print $1 }' | while read s; do f=$s ; echo "f=$f" ;
done ; echo "f=$f"
f=foo
f=bar
f=
Regards
Rodolfo Martínez
On Fri, Sep 18, 2009 at 9:43 AM, Gonzalo Servat <[email protected]> wrote:
> 2009/9/19 Rodolfo Martínez <[email protected]>:
>> 'while' continues until read fails, there is a 3rd 'read' (when it
>> fails) that clears 'f'
>> [mar...@amartir01 ~]$ set -x ; echo -n "foo|bar" | awk 'BEGIN{RS="|"}{
>> print $1 }' | while read s; do f=$s ; echo "f=$f" ; done ; echo "f=$f"
>> + set -x
>> + awk 'BEGIN{RS="|"}{ print $1 }'
>> + read s <== First read
>> + echo -n 'foo|bar'
>> + f=foo
>> + echo f=foo
>> f=foo
>> + read s <== Second read
>> + f=bar
>> + echo f=bar
>> f=bar
>> + read s <== Third read, the one that clears 'f'
>> + echo f=
>> f=
>> ++ echo -ne '\033]0;mar...@amartir01:~'
>
> Yep, however, he is concerned with the variable 'f' being blank, not 's'.
>
> - Gonzalo
> --
> SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
> Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
>
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html