I have a script like this:
#/bin/bash
check(){
if [ "$1" == "" ];then
exit 1
fi
echo "return value"
}
echo "Before"
var=$(check $1)
echo "After"
I expect that when no argument is passed into check(), the program will exit, and therefore "After" will not be printed out.
However, the code "exit 1" only exits the function rather that the program when the return value is assigned to a variable "var".
Does anyone know how to achieve this?
Thanks in advance.