It seems there could be 2 parts to this. The first is to know when you're executing in a source
d script instead of an executed one. That can be found in this answer, and for bash they suggest:
[[ "$0" != "$BASH_SOURCE" ]] && sourced=1 || sourced=0
to tell whether or not you are being sourced.
If you are being sourced, you'd want to use return
instead of exit
.
You could store that function in a variable with something like
if [[ $sourced -eq 1 ]]; then
ret=return
else
ret=exit
fi
and then when you want to use the appropriate one you'd just use
$ret 1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…