shraddha verma
New Member
What does -z flag mean in shell script used in if condition
if [[ -z $SOMEVARIABLE ]]; then
echo "Do something here .... "
if [ -z $SOMEVARIABLE ]; then
echo "Do something here .... "
if test -z $SOMEVARIABLE
help test
touch test
touch testfile
#or better
touch checkthis
If I remember rightly, there is a slight difference between using single square brackets [ ] and double [[ ]] square brackets too.
... and that's a good reason, isn't it Jas, for not naming a file you are testing as "test"?
For example, you would not create an empty file
Code:touch test
Better would be
Code:touch testfile #or better touch checkthis
Calling a file "test" could cause conflict with the command.
Welcome @shraddha verma to linux.org, hope you enjoy your stay here
Wizard
which test
Just a BTW - double brackets support shell globbing, I've been reading an article here
https://linuxacademy.com/blog/linux/conditions-in-bash-scripting-if-statements/
... that illustrates about 5 differences between single and double, it's 2012, and Jas could say if it is still current.
Cheers
Wizard