比较一个变量和多个常量
Compare a variable to multiple constants
我想将变量 NUM 与数字 1 到 6 进行比较,而不必为每个数字编写查找语句。
编辑:我想声明为 "if NUM is not equal to 1, 2, 3, 4, 5 or 6 then do these things"
我试过了
if [ "$NUM" != [1-6] ] ; then
some commands
fi
除了这似乎不起作用。
与正则表达式比较:
if [[ ! "$NUM" =~ ^[1-6]$ ]]; then
我想将变量 NUM 与数字 1 到 6 进行比较,而不必为每个数字编写查找语句。
编辑:我想声明为 "if NUM is not equal to 1, 2, 3, 4, 5 or 6 then do these things"
我试过了
if [ "$NUM" != [1-6] ] ; then
some commands
fi
除了这似乎不起作用。
与正则表达式比较:
if [[ ! "$NUM" =~ ^[1-6]$ ]]; then