0
set temp = "sunny45"

if [ - z $temp ]; then echo "empty" ; else echo "not empty" ; fi

The above code is giving below error when i tried this code on unix terminal

if: Expression syntax.

Please suggest should i source any thing in file and what should ne the file name of this code present.

2 Answers 2

2

Wipe spaces around equal sign and between - and z, then enclose variable in double-quotes:

temp="sunny45"

if [ -z "$temp" ]; then echo "empty" ; else echo "not empty" ; fi
Sign up to request clarification or add additional context in comments.

Comments

1

You have multiple syntax errors. Probably try with http://shellcheck.net/ before asking for human help.

set will not set a regular variable. I'm guessing you want

temp="sunny45"

where you need to make sure there is no whitespace on either side of the equals sign.

The -z in the test similarly needs to be a single token, with no internal whitespace. You also need to quote the variable.

if [ -z "$temp" ]; then

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.