bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A note for read builtin


From: Greg Wooledge
Subject: Re: A note for read builtin
Date: Wed, 16 Jun 2010 14:03:12 -0400
User-agent: Mutt/1.4.2.3i

On Wed, Jun 16, 2010 at 07:47:03PM +0200, Krzysztof ??elechowski wrote:
> The description of the read builtin [19] would benefit of the following note:
> Warning: A pipeline of the form { echo 1 2 | read a b; } is not useful.  Use 
> { 
> read<<<"1 2" a b; } instead.

That kind of advice is certainly welcome in tutorials, guides, and so on
which are teaching shell programming.  I don't really think it needs to
go into the manual, though.  There are hundreds, if not thousands, of
things you should _not_ do, that shouldn't have to be stated in the
reference manual.  This is just one of them.

The reason echo | read fails is because a pipeline runs each component
command in a separate subshell.  The read command sets a and b in its
subshell, which has no effect on the value of those variables in the
parent process (the main script).

I cover this issue on <http://mywiki.wooledge.org/BashFAQ/024> and on
<http://mywiki.wooledge.org/SubShell>.



reply via email to

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