Comparing numbers in Bash

前端 未结 8 1726
栀梦
栀梦 2020-11-22 02:03

I\'m starting to learn about writing scripts for the bash terminal, but I can\'t work out how to get the comparisons to work properly. The script I\'m using is:



        
8条回答
  •  不知归路
    2020-11-22 02:51

    In Bash I prefer doing this as it addresses itself more as a conditional operation unlike using (( )) which is more of arithmetic.

    [[ N -gt M ]]
    

    Unless I do complex stuffs like

    (( (N + 1) > M ))
    

    But everyone just has their own preferences. Sad thing is that some people impose their unofficial standards.

    Update:

    You actually can also do this:

    [[ 'N + 1' -gt M ]]
    

    Which allows you to add something else which you could do with [[ ]] besides arithmetic stuff.

提交回复
热议问题