Shell script variable not empty (-z option)

Viewed 163114

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
4 Answers

if [ !-z $errorstatus ] just put a space between ! and -z, like this: if [ ! -z $errorstatus ]

Related