[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: read-command
From: |
Chris F.A. Johnson |
Subject: |
Re: read-command |
Date: |
Wed, 11 Jul 2001 23:55:28 GMT |
On Wed, 11 Jul 2001, Paul Jarc wrote:
> -pbh- <pbh@pdq.net> writes:
> > An easy test is as follows:
> > echo "thank goodness its friday" | read a b; echo "a=$a, b=$b"
>
> bash forks for each command in a pipeline, so the read works, but it's
> in a child process, so it doesn't affect the original shell. You can
> work around it like this:
> read a b < <(echo "thank goodness its friday")
> There are other workaraounds in the FAQ.
A trick not mentioned in the FAQ is to enclose the read command and all
the script that uses the read variables in braces:
echo "thank goodness its friday" | { read a b
echo "a=$a, b=$b"
## whatever else
}
--
Chris F.A. Johnson bq933@torfree.net
=================================================================
c.f.a.johnson@home.com http://cfaj.freeshell.org
cfaj@freeshell.org http://members.home.net/c.f.a.johnson