- To: Daniel Bush <dlb.id.au@xxxxxxxxx>
- Subject: Re: [SLUG] shell scripting help
- From: Rodolfo Martínez <rmtzcx@xxxxxxxxx>
- Date: Fri, 18 Sep 2009 09:40:55 -0500
- Cc: slug <slug@xxxxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=Ydic1AtAs0DCUEx2xN5+zV+NK0EZBwQvHKdHULjfs3M=; b=JplR5xQuWkk24I4lVL99WtoriKnPupLcsRuBPXCHqAuxOfez45AgWHMHtMEK4vDmjB ZRydkRu3jjJ3bfI7Zby/UfqH4a2INmcwcudM1imLaNqy5Y1q3pVh2KTfjZk3RXkd2bg8 ZZYNeUBgzJpNuyxAxWWHkjokPrvMqY+D9Tb/4=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=mBK9m8Qy6Q096020pcPDbkf7Huxt4hYR0NhduUl/u6OnUzx/YsHatO6zRNPFvcPvDu 26o3QZ46NJez8uLcIHeN1v5AGwurN2HpGv8U78Us+I4nNP+O+DQTpV379efxRgPm2hnT dyQ40Qw/s04IS8rkLhOXXn0yY2AvkVDC2vYpw=
'while' continues until read fails, there is a 3rd 'read' (when it
fails) that clears 'f'
[martir@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;martir@amartir01:~'
Rodolfo Martínez
On Fri, Sep 18, 2009 at 8:42 AM, Daniel Bush <dlb.id.au@xxxxxxxxx> wrote:
>
> Hi,
> Writing a little utility to help me on something but having trouble.
> Why does f stay blank?
>
> danb@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