'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:~'



Rodolfo Martínez



On Fri, Sep 18, 2009 at 8:42 AM, Daniel Bush <[email protected]> wrote:
>
> Hi,
> Writing a little utility to help me on something but having trouble.
> Why does f stay blank?
>
> d...@lin4:test$ echo "foo|bar" | awk 'BEGIN{RS="|"}{ print $1 }' | while
> read s; do echo $s; f=$s; done; echo "'$f'"
> foo
> bar
> ''
>
> Regards
> --
> Daniel Bush
> --
> 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

Reply via email to