Bash -eq and ==, what's the diff?

bash, linux

Solution

`-eq` is an arithmetic test.

You are comparing strings.

From `help test`:

Other operators:

  arg1 OP arg2   Arithmetic tests.  OP is one of -eq, -ne,
                 -lt, -le, -gt, or -ge.

When you use `[[` and use `-eq` as the operator, the shell attempts to evaluate the LHS and RHS. The following example would explain it:

$ foo=something
+ foo=something
$ bar=other
+ bar=other
$ [[ $foo -eq $bar ]] && echo y
+ [[ something -eq other ]]
+ echo y
y
$ something=42
+ something=42
$ [[ $foo -eq $bar ]] && echo y
+ [[ something -eq other ]]
$ other=42
+ other=42
$ [[ $foo -eq $bar ]] && echo y
+ [[ something -eq other ]]
+ echo y
y

Problem

Why this works: ``` Output=$( tail --lines=1 $fileDiProva ) ##[INFO]Output = "OK" if [[ $Output == $OK ]]; then echo "OK" else echo "No Match" fi ``` and this not? ``` Output=$( tail --lines=1 $fileDiProva ) ##[INFO]Output = "OK" if [[ $Output -eq $OK ]]; then echo "OK" else echo "No Match" fi ``` What's the difference?? between == and -eq? Thanks!

Original source