How to make sure a variable is not empty with the -z
option ?
errorstatus="notnull"
if [ !-z $errorstatus ]
then
echo "string is not null"
fi
It returns the error :
./test: line 2: [: !-z: unary operator expected
This question is related to
shell
Why would you use -z? To test if a string is non-empty, you typically use -n:
if test -n "$errorstatus"; then echo errorstatus is not empty fi
I think this is the syntax you are looking for:
if [ -z != $errorstatus ]
then
commands
else
commands
fi
Source: Stackoverflow.com