Getting exit code of last shell command in another script
You'd really need to use a shell function in order to accomplish that. For a simple script like that it should be pretty easy to have it working in both zsh and bash. Just place the following in a file:
my_notify() { echo "exit code: $?" echo "PPID: $PPID"}
Then source that file from your shell startup files. Although since that would be run from within your interactive shell, you may want to use $$ rather than $PPID.
One method to implement this could be to use EOF tag and a master script which will create your my_notify script.
#!/bin/bashif [ -f my_notify ] ; thenrm -rf my_notifyfiif [ -f my_temp ] ; thenrm -rf my_tempfiretval=`ls non_existent_file &> /dev/null ; echo $?`ppid=$PPIDecho "retval=$retval" echo "ppid=$ppid" cat >> my_notify << 'EOF'#!/bin/bashecho "exit code: $retval"echo " PPID =$ppid"EOFsh my_notify
You can refine this script for your purpose.