I would like to check if variable is empty or not. I have found several solutions but it doesn't work for me. I am using this code:
#!/bin/bash
if [[ -z "$test" ]]
then
echo not empty
pwd
else
echo empty
fi
For not empty variable, I get this
pc@ubuntu:~$ echo $test
sfdgsdfg asdf dfgf
pc@ubuntu:~$ ./if_test.sh
not empty
pc@ubuntu:~$
However, if I have empty variable, I get also message that it is not empty.
pc@ubuntu:~$ echo $test
pc@ubuntu:~$
pc@ubuntu:~$ ./if_test.sh
not empty
pc@ubuntu:~$
Could someone help me, where is the problem?