Re: sh bug?

From: Julian Elischer <julian_at_elischer.org>
Date: Fri, 28 Jan 2005 00:43:47 -0800
Walter Belgers wrote:
> Julian Elischer wrote:
> 
>>however  echo $$
>>and
>>  ( echo $$ )
> 
> 
> echo is a shell builting (same with ps).
> Apparantly, sh is smart in recognising you are running sh/ps.
> 
> $ echo $$
> 11808
> $ (echo $$)
> 11808
> $ cat x
> #!/bin/sh
> echo $$
> $ (./x)
> 11812
> 
> Walter.


that doesn't prove anything...

./x would have given the same result.

Actually I investigated further..

$ echo $$
13472
$ (
 >  ps -l >/tmp/1
 >  cat /tmp/1
 > ps -l >/tmp/2
 > cat /tmp/2
 > echo $$
 > ) >/tmp/3
$ cat /tmp/3
[...]
  1000 13472  8177   0   8  0  5484  496 wait   S     pa    0:00.01 /rescue/sh
  1000 14482 13472   0   8  0  5484  496 wait   S+    pa    0:00.00 /rescue/sh
  1000 14483 14482   0  96  0  1412  756 -      R+    pa    0:00.00 ps -l
[...]

this shows that it in fact does fork a different shell,
but only if the contents of the group are "complicated enough".

interestingly enough adding "echo $$" inside the group
still prints the original value of 13472 and not 14482
which might be more truthful.
Received on Fri Jan 28 2005 - 07:44:12 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:27 UTC