I have a bash script, where I call
exit somewhere to skip the rest of the script when
getopts doesn't recognize an option or doesn't find an expected option argument.
while getopts ":t:" opt; do case $opt in t) timelen="$OPTARG" ;; \?) printf "illegal option: -%s\n" "$OPTARG" >&2 echo "$usage" >&2 exit 1 ;; :) printf "missing argument for -%s\n" "$OPTARG" >&2 echo "$usage" >&2 exit 1 ;; esac done # reset of the script
source the script in a bash shell. When something is wrong, the shell exits.
Is there some way other than
exit to skip the rest of the script but without exiting the invoking shell?
return doesn't work like for a function call, and the rest of the script will runs.