Out of curiosity, when doing a bash variable comparison (its value being an integer) it's possible to test it against some predefined value either declared as an int or as a string.Sample script:#!/bin/bashf1(){        [ $1 == 1 ] && echo $FUNCNAME: \1\ compared as string}f2(){        [[ $1 -eq 1 ]] && echo $FUNCNAME: \1\ compared as int}f1 $1f2 $1Output:$  ./param.sh 1f1: 1 compared as stringf2: 1 compared as intand$  ./param.sh blah$Both functions behave the same way, and so I'm wondering if there's a preferred way when checking an integer variable?I would go for checking int versus int as it's more strict but I wonder if there are any draw backs doing it with string?In this case, f2() is also more strict about the comparison, i.e. passing a decimal value will break it, whereas f1() will take it no problem.
Is there any major difference when comparing a variable as a string or as an int
bash;shell;test
Yep, lots of differences.  For instance, = checks for exact string equality, but -eq evaluates both expressions arithmetically before checking for equality:$ [  1  -eq 1 ] && echo equal || echo notequal$ [  1  = 1 ] && echo equal || echo notnot$ [ +1 -eq 1 ] && echo equal || echo notequal$ [ +1 = 1 ] && echo equal || echo notnot$ [ 0+1 -eq 1 ] && echo equal || echo notequal$ [ 0+1 = 1 ] && echo equal || echo notnotAlso, the empty string happens to be numerically equal to zero:$ [  -eq 0 ] && echo equal || echo notequal$ [  = 0 ] && echo equal || echo notnotAnd a whole other class of differences appears when you bring the comparison operators in - considering < vs -lt, for instance:$ [[ 2 -lt 10 ]] && echo less || echo notless$ [[ 2 < 10 ]] && echo less || echo notnotThis is because the string 2 is alphabetically after the string 10 (since 1 comes before 2), but the number 2 is numerically less than the number 10.