bug-bash
[Top][All Lists]
Advanced

[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- <address@hidden> 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          address@hidden
        =================================================================
        address@hidden      http://cfaj.freeshell.org
        address@hidden      http://members.home.net/c.f.a.johnson



reply via email to

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