shell scripts and /bin/sh

Hi,
Quick question for ya. If I have a shell script (starts with #!/bin/sh) and
I call another shell script from it, will it spawn another copy of sh, or
does it use the current one? I’m just wondering if in that second script,
if it does start another copy of sh, if I can leave the #!/bin/sh off the
beginning to prevent it from using an extra copy.

TIA
R B Adler

R B Adler <cococr@cs.rpi.edu> wrote:

Hi,
Quick question for ya. If I have a shell script (starts with #!/bin/sh) and
I call another shell script from it, will it spawn another copy of sh, or
does it use the current one? I’m just wondering if in that second script,
if it does start another copy of sh, if I can leave the #!/bin/sh off the
beginning to prevent it from using an extra copy.

It will start another shell. Even if you leave the #!/bin/sh off the
start of the other shell, it will start another shell. (The #!/bin/sh
is magic for the loader thread in Proc32, allowing you to start the
shell scripts with spawn*() or exec*() rather than having to use system().)

If you want to run the other script in the current shell, try using the
… command. e.g.:

… sub_script

-David

QNX Training Services
dagibbs@qnx.com