sh bug?
Julian Elischer
julian at elischer.org
Fri Jan 28 00:44:12 PST 2005
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.
More information about the freebsd-current
mailing list