Comment on TIL: Some surprising code execution sources in bashparentComments−oneshtein1yInstead of `if [[ "${num}" -eq 42 ]]`, bash expects `if [ "${num}" -eq 42 ]` or `if (( num==42 ))`.−tpoacher1yor if test $num -eq 42, which is the most sensible way to do it in my view, since it really makes the point clear that what you're really evaluating is the exit status of the evaluated command(and where '[' is simply an alias to 'test')−jwilk1y"if (( num==42 ))" can exectue code from $num too.−Leynos1yTypeset num as an integer.
Comments
Instead of `if [[ "${num}" -eq 42 ]]`, bash expects `if [ "${num}" -eq 42 ]` or `if (( num==42 ))`.
or if test $num -eq 42, which is the most sensible way to do it in my view, since it really makes the point clear that what you're really evaluating is the exit status of the evaluated command
(and where '[' is simply an alias to 'test')
"if (( num==42 ))" can exectue code from $num too.
Typeset num as an integer.