2

I am writing a Bash script and I am new to it. When I run it I get this error:

./greet: line 14: syntax error in conditional expression

./greet: line 15: syntax error near `then'
./greet: line 15: `   then '

The lines of code its throwing on are these:

if [[ $hour -lt 0 || $hour -gt 23]]
   then
      echo "Please Enter a value between 0-23"
      exit 1
fi
#

I have tried putting spaces after the "then" and rewriting it multiple times.

1
  • 1
    Save yourself some trouble with shellcheck Commented May 8, 2019 at 22:15

1 Answer 1

1

In the if statement, you need a space before ]]. The [[ and ]] have to be their own "words" as defined by the shell, so surrounded by whitespace.

Sign up to request clarification or add additional context in comments.

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.