Well, the question is not very clear: what did the author of the original want after catching the error in the script source, however, as an entry point for the solution, it will be enough:
You can set the trap on ERR and handle the error inside the found script. The following are two scenarios: one with a script source using "set -e", and the other with a script source code NOT using "set -e".
The primary script calls the secondary script with the specified "set -e" and detects an error:
[galaxy => ~]$ cat primary.sh
The main script calls a secondary script without "set -e" and detects an error:
[galaxy => ~]$ cat primary.sh
As a bonus: catching an error in the script source and continuing:
[galaxy => ~]$ cat primary.sh #!/bin/sh echo 'Primary script' i=0 while [ $i = 0 ]; do i=1 trap 'echo "Got an error from the secondary script"; break' ERR source secondary.sh done trap - ERR echo 'Primary script exiting' [galaxy => ~]$ cat secondary.sh #!/bin/sh echo 'Secondary script' echo 'Secondary script generating an error' false echo 'Secondary script - should not be reached if sourced by primary.sh' [galaxy => ~]$ ./primary.sh Primary script Secondary script Secondary script generating an error Got an error from the secondary script Primary script exiting [galaxy => ~]$
source share