shell script puzzler

Leo de Wit leo at philmds.UUCP
Sat Apr 8 19:49:24 AEST 1989


In article <3286 at ttrdc.UUCP> levy at ttrdc.UUCP (Daniel R. Levy) writes:
    []
|If you want to see that pid at the END of the subshell, just
|
|(
|...
|exec echo '$$'
|#nothing from here on will be executed
|...
|)

Script started on Sat Apr  8 11:30:51 1989
philmds> (exec echo '$$')
$$
philmds> ^D

script done on Sat Apr  8 11:31:20 1989

A pid of '$$'? C'mon 8-).

What you can do:

	 $ (eval echo '$$')  # or perhaps just (echo $$)

but this will evaluate to the parent's pid (since $$ is set only once,
in the parent; the child is just a forked off copy).
Alternatively,

	 $ sh -c "echo \$\$"

does give its pid correctly. Note however that this requires an exec,
and does not preserve the current shell's context (like shell variables
etc.).

	 Leo.



More information about the Comp.unix.wizards mailing list