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).exitcommand in the file being sourced then normally the shell will be terminated and no commands after thesourcecommand will be executed. When you are sourcing a file no new shell is started. --- The variantssh name.shandbash name.shdo not requirename.shto be executable! You can use them if you do not need to modify your environment inname.shand have it in the parent script.