0

I have this code snippet from one of my scripts:

#!/bin/bash

abc=4

if "$abc" == "4" && grep https://download.abc.com abc.log; then
    echo "True"
else
    echo "False"
fi

Expected output:

True

Actual output:

./abc.sh: line 5: 4: command not found
False

What is wrong in my if statement that throws this syntax error?

Bogdan
  • 103
  • 1
  • 12
  • What ar you trying to do here: `grep https://download.abc.com abc.log`. This part fails – Jotne Aug 28 '19 at 05:53
  • @Jotne No, the error is that `if "$abc"` tries to run the value of `abc` as a command. – tripleee Aug 28 '19 at 05:54
  • 1
    @Bogdan: The syntax is `if COMMAND; then ....`, and the `if` succeeds if the command returns exit status 0. In your case, the command is `$abc`, which evaluates to `4`, and you don't have a command of this name. – user1934428 Aug 28 '19 at 05:55
  • 3
    The fix is `if [[ "$abc" = "4" ]] && grep -q 'https://download.abc.com' abc.log; then` – tripleee Aug 28 '19 at 05:56
  • this is what I was looking for. I knew it must be some sort of syntax error. thank you. – Bogdan Aug 28 '19 at 05:57

0 Answers0