Re: ksh - no "read" from pipe, but not common "subshell" issue
From: Dan Mercer (dmercer_at_mn.rr.com)
Date: 11/18/05
- Next message: John DuBois: "Re: ksh - no "read" from pipe, but not common "subshell" issue"
- Previous message: dan.rickhoff_at_comcast.net: "Re: ksh - no "read" from pipe, but not common "subshell" issue"
- In reply to: Lars Kellogg-Stedman: "Re: ksh - no "read" from pipe, but not common "subshell" issue"
- Next in thread: Bill Marcum: "Re: ksh - no "read" from pipe, but not common "subshell" issue"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 17 Nov 2005 23:22:03 GMT
"Lars Kellogg-Stedman" <8273grkci8q8kgt@jetable.net> wrote in message news:t1132253029.p14767.r288016685@lars.jetable.net...
: > $ print "Hello World." | { read; print "$REPLY"; }
: >
: > $ print "Hello World.\nHow's things?" | while read; do print "$REPLY";
: > done
: >
: > I very seriously doubt that the problem is that the "read" is in a
: > subshell below the shell of the "print".
:
: I think maybe it is. Your first example is functionally equivalent to:
:
: $ print "Hello World." | read; print "$REPLY";
:
: In this casae, read is part of a pipeline and is executed in a subshell
: environment, so the variable it sets is lost by the time the print
: command executes.
Not in ksh93 which the OP claims to be using.
Dan Mercer
:
: However, if you were to rewrite it as:
:
: print "Hello World." | ( read; print "$REPLY"; )
:
: You would get the results you expect; in this case, read is *not* part a
: pipeline -- the enclosing *shell* is part of the pipline -- so it
: executes at the same shell level as the print command.
:
: Similarly, your second example:
:
: $ print "Hello World." | while read; ...
:
: Also has the read command executing as part of a pipeline. Again, if
: you actually put the read in a shell with your print command, it all
: executes at the same level:
:
: $ print "Hello World." | ( while read; do print "$REPLY"; done; )
:
: Reading through:
:
: http://www.monkey.org/openbsd/archive2/bugs/200306/msg00034.html
:
: The single unix specification *allows* the final command in a pipeline
: to execute in the current environment, but does not require it, so the
: above behavior is perfectly legal.
:
: -- Lars
:
: --
: Lars Kellogg-Stedman <8273grkci8q8kgt@jetable.net>
: This email address will expire on 2005-11-23.
:
- Next message: John DuBois: "Re: ksh - no "read" from pipe, but not common "subshell" issue"
- Previous message: dan.rickhoff_at_comcast.net: "Re: ksh - no "read" from pipe, but not common "subshell" issue"
- In reply to: Lars Kellogg-Stedman: "Re: ksh - no "read" from pipe, but not common "subshell" issue"
- Next in thread: Bill Marcum: "Re: ksh - no "read" from pipe, but not common "subshell" issue"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|