Floating point comparison in shell

前端 未结 7 1402
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 17:38

Can you please suggest to me the syntax for doing floating point comparison in a Bash script? I would ideally like to use it as part of an if statement. Here is

7条回答
  •  暖寄归人
    2020-11-27 18:07

    ### The funny thing about bash is this:
    > AA=10.3
    > BB=10.4
    ### It needs `$` for compare
    > [[ $AA > $BB ]] && echo Hello
    > [[ $AA < $BB ]] && echo Hello
    Hello
    

    Yeah, I know it's cheating but it works. And scientific notation does not work here.

提交回复
热议问题