【发布时间】:2017-06-11 01:41:33
【问题描述】:
我想检查我的 bash 脚本,如果变量等于值 1 或等于值 2。
我不想使用这样的东西,因为当变量等于 1 或 2 时,“if true statements”是相同的(一些大的回显文本)。我想避免数据冗余。
if [ $1 == 1 ] ; then echo number 1 ; else
if [ $1 == 2 ] ; then echo number 2 ; fi
更多类似
if [ $1 == 1 OR 2 ] ; then echo number 1 or 2 ; fi
【问题讨论】:
-
旁白:
==在[中不是有效的比较运算符。 Bash 允许将其作为扩展名,但 relevant standard 仅指定=用于字符串比较。
标签: linux bash if-statement parameters equality