Check whether one number equals another number in bash

后端 未结 4 1811
庸人自扰
庸人自扰 2020-12-24 07:02

I\'ve been trying to compare whether two numbers in Bash are equal (and print a message if they are equal), but I\'m getting some strange error messages for this simple prog

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-24 07:41

    For the first error message, remove the dollar sign $ and no spaces are allowed around the equal sign =

    x=3
    

    For the second error message, insert a space and a dollar sign $ before x and a space after 3

    if [ $x -eq 3 ]
    

    As @loentar correctly pointed out, it must be -eq and neither = nor ==.

提交回复
热议问题