How to force script.sh to run as subshell not child?

375 Views Asked by At

I have several kinds of buildA.sh, buildB.sh, ... scripts which compile some codes. I also have a general script common.sh which do pre-process, set environments and set trap command.

cat common.sh 
~~~
./buildA.sh  #call build.sh, other build.sh run in other directory.
~~~

I need to make build.sh run as subshell from common.sh to re-use trap command and non-export variable access to common.sh Is there any way to do that or workaround?

1

There are 1 best solutions below

2
redseven On

You have to source the script to run it in the current shell. This is not a subshell, but I think that's what you really want:

source build.sh

Or the equivalent simple syntax:

. build.sh