0

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?

OfusJK
  • 676
  • 1
  • 5
  • 13

1 Answers1

2

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
redseven
  • 849
  • 6
  • 11
  • I think using source is the most acceptable option. I thought there is other way. source would be enough. thanks redseven and Philippe. – OfusJK Dec 16 '22 at 15:34
  • If I use "source", the $LINE and $BASH_SOURCE always return that line "source build.sh" not the real contents.                                ---- trap 'exitcode=$? LINE=$LINENO echo "[ERROR]: $BASH_SOURCE: $LINE: $BASH_COMMAND: exit $exitcode" exit $exitcode 'ERR EXIT ... ----- – OfusJK Dec 16 '22 at 16:42