shell script puzzler
Root Boy Jim
rbj at dsys.icst.nbs.gov
Fri May 19 02:01:46 AEST 1989
? From: Chris Torek <chris at mimsy.uucp>
? In article <995 at etnibsd.UUCP> vsh at etnibsd.UUCP (Steve Harris) writes:
? >Here is one for the shell programming gurus: given the following
? >shell script, how can I get the subshell to echo its true pid??
? >(I am running SunOS 3.4, if it matters).
I'm running SunOS 3.5.
? >#! /bin/sh
? >echo $$ # echos pid of parent shell
? >( echo $$ ) # echos same pid
? At least in 4BSD, you cannot. `sh' sets up `$$' near the top of main()
? and never changes it (except when running a script, in lieu of starting
? a new /bin/sh to run it).
? --
? In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
? Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
Chris hinted that you must run another sh. Here's how:
#! /bin/sh
echo shell pid $$
(sh -c 'echo subshell pid $$')
(echo 'echo another subshell pid $$' | sh)
(eval 'echo why is $$ the parent pid?')
echo shell pid $$
For some reason, the eval form doesn't work.
Root Boy Jim is what I am
Are you what you are or what?
More information about the Comp.unix.wizards
mailing list