79372643

Date: 2025-01-20 21:12:52
Score: 2.5
Natty:
Report link

The following trick allows the script to gracefully exit without terminating the shell, whether sourced or direct execution:

instead of exit, use this:

[[ $PS1 ]] && return $? || exit $?

Alternately, define this function and call it instead of exit:

    __EXIT__()
   {
       [[ $PS1 ]] && return $1 || exit $1
   }
    ....
    __EXIT__ $?
Reasons:
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: Shahid