Mail Archives: djgpp-workers/1996/10/01/18:35:36
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 -