Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!nrl-cmf!ukma!tut.cis.ohio-state.edu!osu-cis!att!ttrdc!levy From: levy@ttrdc.UUCP (Daniel R. Levy) Newsgroups: comp.unix.wizards Subject: Re: shell script puzzler Keywords: /bin/sh Message-ID: <3286@ttrdc.UUCP> Date: 26 Mar 89 05:01:15 GMT References: <995@etnibsd.UUCP> <16489@mimsy.UUCP> Lines: 32 [Chris Torek] < >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). < < >#! /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). Yup that's basically what you have to do, start a new shell explicitly. If you want to see that pid at the END of the subshell, just ( ... exec echo '$$' #nothing from here on will be executed ... ) Since the exec retains the same pid, it works. Of course anything from there to the end of the subshell gets pitched... JUST a picky little detail.... -- Daniel R. Levy UNIX(R) mail: att!ttbcad!levy AT&T Bell Laboratories 5555 West Touhy Avenue Any opinions expressed in the message above are Skokie, Illinois 60077 mine, and not necessarily AT&T's.