[lug] Bash question
Zan Lynx
zlynx at acm.org
Sat Jul 10 03:07:52 MDT 2004
On Sat, 2004-07-10 at 02:52, Daniel Webb wrote:
> $ X=nothing
> $ read X <<< $(echo something)
> $ echo $X
> something
>
> $ X=nothing
> $ echo something | read X
> $ echo $X
> nothing
>
> Why???
>
"Each command in a pipeline is executed as a separate process (i.e., in
a subshell)." -- bash man page
Variables inside a subshell stay in there.
If you want to feed a command into a read and do stuff to it, a handy
method is this:
echo something | while read X; do something $X; done
--
Zan Lynx <zlynx at acm.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20040710/7488576d/attachment.pgp>
More information about the LUG
mailing list