{} grouping in sh and ksh
William E. Davidsen Jr
davidsen at steinmetz.ge.com
Wed Oct 5 23:57:09 AEST 1988
I recently posted an answer to a question and have been told that me
reply is true for ksh, but not for sh. Let me clarify the action of both
shells. I tested the sh operation on both V.2 and V7, so I am reasonably
certain of the action.
In sh, actions grouped by {} delimiters will be treated as a unit and
may be used with &&, ||, and redirection. If redirection is used the
commands will be executed in a subshell. After the commands have been
run, if a subshell is not used the working directory is reset, such that
it always works as if a subshell were used.
Ex: { cd ..; ps -l; pwd; ps -l; } && pwd
{ cd ..; ps -l; pwd; ps -l; } > x && pwd
In the example with redirection the first ps will show a subshell
running.
Even if a subshell is used, the last command is execed without a
fork, so the second ps will *never* show a subshell. This muddied the
water when I was investigating the action.
In ksh a subshell is never used. After execution of the commands the
working directory is not reset. This is exactly as documented. The
examples above will produce the same output.
I apologize if this mislead anyone, I know how ksh works, and a simple
test with sh before my last posting didn't show the details.
--
bill davidsen (wedu at ge-crd.arpa)
{uunet | philabs}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me
More information about the Comp.unix.questions
mailing list