delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1996/10/01/18:35:36

Message-ID: <3251C377.3134@cs.com>
Date: Tue, 01 Oct 1996 18:20:55 -0700
From: "John M. Aldrich" <fighteer AT cs DOT com>
Reply-To: fighteer AT cs DOT com
Organization: Three pounds of chaos and a pinch of salt
MIME-Version: 1.0
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
CC: Daisuke Aoyama <jack AT st DOT rim DOT or DOT jp>, djgpp-workers AT delorie DOT com
Subject: Re: bash 1.14.7 is available
References: <Pine DOT SUN DOT 3 DOT 91 DOT 961001084035 DOT 23760C-100000 AT is>

Eli Zaretskii wrote:
> 
> I found something strange about the `(commands)' construct.  Try this:
> 
>         bash -c '(cd .. | ls)'
> 
> You will see the listing of the *current* directory, not of its parent,
> from `ls'.  I've tried this with a Unix `sh', and it works the same, but
> `ms_sh' does produce the listing of the parent (and I do find this latter
> behavior more intuitive).  What am I missing here?

Forgive me for intruding here, but I think I can take a guess.  Under
MS-DOS, asynchronous pipes are not possible.  When you open a pipe for
reading, the program is executed in its entirety and its output is
redirected to the file pointer.  When you open it for writing, the
program is not executed until the pipe is closed.  However, in the
latter case I believe that the command is actually evaluated by the
shell at the time of the pipe's opening.  (Please correct me if I'm
wrong here.)  Thus, the pipe to 'ls' would be opened before 'cd' had
actually changed the directory, causing its environment to specify the
current directory instead of the parent.  If this is indeed the case
then you couldn't just use an ordinary 'pipe()' call in the shell; a
workaround would have to be found.  Perhaps 'ms_sh' addresses this
problem while the others do not?

> Btw, if you replace `|' with a `;', it lists the parent directory.

For obvious reasons.  (The processes are executed sequentially, not
(a)synchronously.)  :)

-- 
John M. Aldrich <fighteer AT cs DOT com>                      

* Anything that happens, happens.
* Anything that, in happening, causes something else to happen,
  causes something else to happen.
* Anything that, in happening, causes itself to happen again, happens
  again.
* It doesn't necessarily do it in chronological order, though.
 
                                       --- Douglas Adams

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019