I want to source a file eg name.sh from another script and check the return code and decide on it's error code. If I use
source name.sh
then if name.sh return non-zero return code my main script stop to run but I need to decide on exit code weather to continue or stop.
If I use
ret_code="`source name.sh`"
echo $ret_code
then ret_code is null and no error code is printed. I can't use these:
sh name.sh
./name.sh
bash name.sh
because name.sh is not executable and I don't want it to be executable
source name.sh
; this is equivalent tobash name.sh
(assuming $SHELL is bash).exit
command in the file being sourced then normally the shell will be terminated and no commands after thesource
command will be executed. When you are sourcing a file no new shell is started. --- The variantssh name.sh
andbash name.sh
do not requirename.sh
to be executable! You can use them if you do not need to modify your environment inname.sh
and have it in the parent script.