This question already has an answer here:

I am trying to run a small script which check for two variables to see if they are empty or not. I am getting the correct output but if also shows me error for missing right parenthesis. I tried using double parenthesis as well as round bracket but didn't work.


 if ([ -z "$var"] && [ -z "$non"])
    echo "both empty"

    echo "has data"


line 6: [: missing `]'
has data

marked as duplicate by jasonwryan, jimmij, Archemar, muru, Gilles shell-script Sep 14 '15 at 21:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


You need a space bettween "$non" and ], and you don't need ()'s:

if [ -z "$var" ] && [ -z "$non" ]

As Andy Dalton said in his answer you need a space between "$non" and the closing square parentheses ] like this:

[ -z "$non" ]

I just want to add a bit of motivation why this is needed. In bash the square parentheses are commands (you can try man [ to see, it's the manual for the test command), so you need the space for bash to figure out which command you are invoking.

Not the answer you're looking for? Browse other questions tagged or ask your own question.