Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!mcvax!hp4nl!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.unix.wizards Subject: Re: shell script puzzler Keywords: /bin/sh Message-ID: <998@philmds.UUCP> Date: 8 Apr 89 09:49:24 GMT References: <995@etnibsd.UUCP> <16489@mimsy.UUCP> <3286@ttrdc.UUCP> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 35 In article <3286@ttrdc.UUCP> levy@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.