Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Jan 2000 17:55:18 -0500
From:      "Crist J. Clark" <cjc@cc942873-a.ewndsr1.nj.home.com>
To:        freebsd-questions@FreeBSD.ORG
Subject:   Re: sh(1) Messing with My Mind
Message-ID:  <20000120175518.F72914@cc942873-a.ewndsr1.nj.home.com>
In-Reply-To: <200001202140.WAA05161@dorifer.heim3.tu-clausthal.de>; from olli@dorifer.heim3.tu-clausthal.de on Thu, Jan 20, 2000 at 10:40:08PM %2B0100
References:  <867h6j$1kk4$1@atlantis.rz.tu-clausthal.de> <200001202140.WAA05161@dorifer.heim3.tu-clausthal.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Jan 20, 2000 at 10:40:08PM +0100, Oliver Fromme wrote:
> Crist J. Clark <cjc@cc942873-a.ewndsr1.nj.home.com> wrote in list.freebsd-questions:
>  > [...]
>  > seems to have muddled my thoughts this morning. Why does this happen:
>  > 
>  > $ echo 3 | read NUM
>  > $ echo $NUM  
>  > 
> 
> Because the read command is executed in a subshell when it is
> in a pipe.  When the pipe ends, the subshell terminates, and
> its environment variables are gone.

*grumble-grumble*

I could swear I have done this in the past.

[snip]

> You usually solve this problem by using command substitution
> ("backticks"):
> 
>    NUM=`echo 3`

That is what I ususally do if the command generating the output is
short. There are two reasons I do not want to do this,

(1) The command generating the output is long. (An awk command-line
    program being fed by another pipe.)

(2) A read would break up the output just the way I want. (The output
    happens to be a number followed by a date(1)-type string. A 
    'read NUM DATE' command would break it up exactly how I want.)

And although it does not impact me, there is another reason, and one
of the best ones, that someone would rather pipe to read than
backtick,

(3) The backticked argument cannot have nested backticks.

Anyway, I guess I need to find a workaround. I figured I was missing
something obvious (something I already knew). Thanks for pointing it
out.
-- 
Crist J. Clark                           cjclark@home.com


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000120175518.F72914>