Reputation: 55690
The following bash script is giving me problems:
#!/bin/bash
if [[ $VAR -eq "<EMPTY>" ]]; then echo "Hello World!"; fi
Bash fails, complaining:
line 3: [[: <EMPTY>: syntax error: operand expected (error token is "<EMPTY>")
How can I test if the string contained in VAR
is equivalent to the string "<EMPTY>"
?
Upvotes: 0
Views: 388
Reputation: 241918
Inside [[ ... ]]
, -eq
has a different meaning: it is used to compare integers. You can use (( ... ))
to compare integeres with normal operators, though. Use the following for strings:
[[ $VAR == "<EMPTY>" ]]
Upvotes: 2
Reputation: 168646
You are using the wrong operator. ==
is for strings, -eq
is for numbers.
#!/bin/bash
if [[ $VAR == "<EMPTY>" ]]; then echo "Hello World!"; fi
Upvotes: 4