mardi 28 novembre 2017

bash if statement gives syntax error in console, but works properly

Using a bash if statement to check if two numbers in two different arrays are equal. It seems that on the condition where the statement should evaluate to false (ie. the two numbers are not equal) then console displays a syntax error.

Code in question:

for((i=0;i<=passes256Size;i+=1));do
    if((${passes212[$i]}==${passes256[$i]})); then
        passesBoth[$i]=${passes256[$i]}     
    fi
done

Error:

./partii.sh: line 46: 102==: syntax error: operand expected (error token is "=")
./partii.sh: line 46: ==103: syntax error: operand expected (error token is "==103")

The program still runs and gives me the desired result, however I get those two errors coming up during run time. Is there any way to fix this issue?

Aucun commentaire:

Enregistrer un commentaire