I would like to test if a condition is true or false. Here is a sample bash script:
#!/bin/bash set -x var=foo if [[ $var==bar ]] then echo $var is bar else echo $var is not bar fi set +x
I expect that the output will be
foo is not bar, but I get the following output instead:
foo is bar
While viewing the debug output, I noticed that the condition was being evaluated with
+ var=foo + [[ -n foo==bar ]] + echo foo is bar foo is bar + set +x
On the Bash Conditional Expressions man page it says
True if the length of string is non-zero.
But I'm not interested in whether the string length is non-zero, but rather whether the two strings are equal to each other.