1

I'm trying to compare two strings, which are identical as I can see in the log of debugging the next lines:

echo "line: $line"
echo "fingerPrints:$i ${fingerPrints[$i]}"

31 + echo 'line: DCD0 5B71 EAB9 4199 527F 44AC DB6B 8C1F 96D8 BF6D'  
32 + echo 'fingerPrints:1 DCD0 5B71 EAB9 4199 527F 44AC DB6B 8C1F 96D8 BF6D'

But when I try a line after to compare those strings,

if ["$line" ne "${fingerPrints[$i]}"]; then

this is what's happening:

33 + '[DCD0 5B71 EAB9 4199 527F 44AC DB6B 8C1F 96D8 BF6D' ne
'DCD0 5B71 EAB9 4199 527F 44AC DB6B 8C1F 96D8 BF6D]' ./gentoo-stage.sh:

line 33: [DCD0 5B71 EAB9 4199 527F 44AC DB6B 8C1F 96D8 BF6D: command not found

I am not trying to check if one string contains the other, just if they are euqal.

Same results when I try != instead of ne.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
RD7
  • 628
  • 4
  • 9
  • 20
  • Possible duplicate of [How do I compare two string variables in an 'if' statement in Bash?](http://stackoverflow.com/questions/4277665/how-do-i-compare-two-string-variables-in-an-if-statement-in-bash) – Benjamin W. Mar 19 '16 at 23:13

1 Answers1

2

You must put a space after [ and before ]. So instead of:

if ["$line" ne "${fingerPrints[$i]}"]; then

Write like this:

if [ "$line" ne "${fingerPrints[$i]}" ]; then

And "ne" is not an operator. You probably meant != there:

if [ "$line" != "${fingerPrints[$i]}" ]; then

Btw -ne is used for comparing integer expressions, and you're comparing strings, so != is really the only operator that makes sense here.

janos
  • 120,954
  • 29
  • 226
  • 236