|
Home > Archive > Unix Shell > March 2004 > problem with (...)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
problem with (...)
|
|
| Reiner Funck 2004-03-26, 11:47 am |
| Hallo,
sorry, another question about (...)
The description is:
Placing a list of commands between parentheses causes a subshell
to be created, and each of the commands in list to be executed
in that subshell.
Definition of subshell:
Son-process for current shell.
But the sequence
echo $$
( echo $$ )
brings identical process-ID's
Wy?
Thanks, Reiner
| |
| Michael Tosch 2004-03-26, 11:47 am |
| In article <c418nb$2dnaf5$1@uni-berlin.de>, Reiner Funck <reiner.funck@dwd.de> writes:
> Hallo,
>
> sorry, another question about (...)
> The description is:
> Placing a list of commands between parentheses causes a subshell
> to be created, and each of the commands in list to be executed
> in that subshell.
> Definition of subshell:
> Son-process for current shell.
> But the sequence
> echo $$
> ( echo $$ )
> brings identical process-ID's
> Wy?
> Thanks, Reiner
>
IMHO it depends on the shell implementation if a new process is
spawned or not.
--
Michael Tosch
IT Specialist
HP Managed Services Germany
Phone +49 2407 575 313
Mail: michael.tosch@hp.com
| |
| Alexis Huxley 2004-03-26, 11:47 am |
| >> sorry, another question about (...)
>
> IMHO it depends on the shell implementation if a new process is
> spawned or not.
Actually, I think that the *current* shell will do the substitution
of $$ for the *current* shell's process ID, and then the
subshell (or not depending on shell implementation) will do
echo <whatever-number-the-parent-shell-substituted-in>
So I think
( echo $$ )
will *ALWAYS* produce the current shell's PID. What should not
(but might depending on shell implementation) would be:
( eval echo \$\$ )
This is somewhat analoguous to:
sh -c "echo $$"
and
sh -c 'echo $$'
In both first cases the $$ is substituted by the current shell,
in both second cases it is substituted by the child shell.
Alexis
| |
| Villy Kruse 2004-03-26, 11:47 am |
| On Fri, 26 Mar 2004 14:16:41 +0000 (UTC),
Michael Tosch <eedmit@NO.eed.SPAM.ericsson.PLS.se> wrote:
As the purpose for putting shell commands in parenteses is to make
them run in a subshell it is rather odd if the shell shouldn't
crate a subshell for those comands.
Villy
| |
| Dan Mercer 2004-03-26, 2:03 pm |
|
"Reiner Funck" <reiner.funck@dwd.de> wrote in message news:c418nb$2dnaf5$1@uni-berlin.de...
: Hallo,
:
: sorry, another question about (...)
: The description is:
: Placing a list of commands between parentheses causes a subshell
: to be created, and each of the commands in list to be executed
: in that subshell.
: Definition of subshell:
: Son-process for current shell.
: But the sequence
: echo $$
: ( echo $$ )
: brings identical process-ID's
: Wy?
: Thanks, Reiner
:
$$ is evaluated when ksh is exec'd. A subshell is a forked process -
it inherits the environment of the original process. No variables
are re-evaluated, including that of $$. So there is no quoting
or trick to get the process id of the subshell.
Dan Mercer
| |
| Dan Mercer 2004-03-26, 2:04 pm |
|
"Michael Tosch" <eedmit@NO.eed.SPAM.ericsson.PLS.se> wrote in message news:c41e09$q0e$1@newstree.wise.edt.ericsson.se...
: In article <c418nb$2dnaf5$1@uni-berlin.de>, Reiner Funck <reiner.funck@dwd.de> writes:
: > Hallo,
: >
: > sorry, another question about (...)
: > The description is:
: > Placing a list of commands between parentheses causes a subshell
: > to be created, and each of the commands in list to be executed
: > in that subshell.
: > Definition of subshell:
: > Son-process for current shell.
: > But the sequence
: > echo $$
: > ( echo $$ )
: > brings identical process-ID's
: > Wy?
: > Thanks, Reiner
: >
:
: IMHO it depends on the shell implementation if a new process is
: spawned or not.
Wrong answer.
Dan
:
: --
: Michael Tosch
: IT Specialist
: HP Managed Services Germany
: Phone +49 2407 575 313
: Mail: michael.tosch@hp.com
:
:
| |
| Dan Mercer 2004-03-26, 2:04 pm |
|
"Alexis Huxley" <ahuxley@gmx.net> wrote in message news:slrnc68hub.fdt.ahuxley@dione.no-ip.org...
: >> sorry, another question about (...)
: >> The description is:
: >> Placing a list of commands between parentheses causes a subshell
: >> to be created, and each of the commands in list to be executed
: >> in that subshell.
: >> Definition of subshell:
: >> Son-process for current shell.
: >> But the sequence
: >> echo $$
: >> ( echo $$ )
: >> brings identical process-ID's
: >
: > IMHO it depends on the shell implementation if a new process is
: > spawned or not.
:
: Actually, I think that the *current* shell will do the substitution
: of $$ for the *current* shell's process ID, and then the
: subshell (or not depending on shell implementation) will do
:
: echo <whatever-number-the-parent-shell-substituted-in>
:
: So I think
:
: ( echo $$ )
:
: will *ALWAYS* produce the current shell's PID. What should not
: (but might depending on shell implementation) would be:
:
: ( eval echo \$\$ )
That won't work either. $$ is evaluated when a shell is exec'd. A subshell
is merely forked.
Dan Mercer
:
: This is somewhat analoguous to:
:
: sh -c "echo $$"
:
: and
:
: sh -c 'echo $$'
:
: In both first cases the $$ is substituted by the current shell,
: in both second cases it is substituted by the child shell.
:
: Alexis
|
|
|
|
|