Re: ksh - no "read" from pipe, but not common "subshell" issue

From: Dan Mercer (dmercer_at_mn.rr.com)
Date: 11/18/05


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.
:



Relevant Pages

  • Re: [SLE] Re: How does .bashrc work in KDE (Konsole) (Conclusion)
    ... I don't change these settings often, I will not spend anymore time on ... You can always source a file from a running shell. ... with a file name argument reads and executes commands from that file. ... executed the "source" command rather than a sub-shell launched ...
    (SuSE)
  • Re: Using os.system() and string concatenation
    ... > I think take those lists and provide them to an os.systemcall. ... > This executes without any errors, but doesn't execute the command ... > supply it to os.systemit executes just fine. ... a shell command out of data from files, ...
    (comp.lang.python)
  • Re: cat /dev/urandom
    ... The command: cat /dev/urandom ... is passed to the shell and the shell executes "cat" and sends ... The command: $ ... it first and then executes it, where "it" is the output of the ...
    (freebsd-questions)
  • Re: what happens when i run ps command on shell prompt?
    ... Executes and retuen to parent process that is shell ... when executing a command from the shell, it forks, then close/open ...
    (comp.unix.programmer)
  • Re: ksh - no "read" from pipe, but not common "subshell" issue
    ... executes at the same shell level as the print command. ... Also has the read command executing as part of a pipeline. ...
    (comp.unix.shell)