New in bash script, have to write a function to check if the first given parameter is empty. Output error message if it is empty, otherwise success.
Use return-statement and the variable $? Output should for example like this:
./test.sh
-> Script failed
; ./test.sh hallo
-> Script OK
.
Thank you!
This is what i have now:
check_parameter() {
var=$1
if [ -z ${var} ]; then
return 1
else
return 0
fi
if [ $?== 0 ]; then
echo " OK. "
else
echo " failed. "
fi
}
check_parameter $1
It seems like the ìf [ -z $var ]
or ìf [ -z ${var} ]
doesn't work.