If you have a look at the manual of Bash, then you read
source filename [arguments]:
Read and execute commands from filename in the current shell environment and return the exit status of the last command executed from filename. If filename does not contain ...
source: man bash
These are two very important properties which are related to your problem:
If your sub_script encounters a subScriptExitCode which is different from zero. It will terminate the main_script instantaneously due to the exit statement.
The main_script will set subScriptExitCode to the exit state of the if-statement. This is zero in case subScriuptExitCode of sub_script equals 0.
if list; then list; [ elif list; then list; ] ... [ else list; ] fi: ... The exit status is the exit status of the last command executed, or zero if no condition tested true.
source: man bash
A possible way to solve your problem, making use only of the properties of source would be:
sub_script:
type -p <package>
[ $? -eq 0 ]
Here, the test command will exit with the state 0 if type p <package> terminated with zero, otherwise the test-command will exit with state 1. This state is then picked up in your main_source as $?. However, since type -p can only return 0 or 1, you can just get rid of the test and reduce sub_script to:
type -p <package>
type [-aftpP] name [name ...]: ... type returns true if all of the arguments are found, false if any are not found.
[source: man bash]
returninstead ofexitinside sub.sh