【发布时间】:2019-01-05 18:57:28
【问题描述】:
我有一个脚本:
#!/bin/bash
echo "You chose $1 and $2 "
if [[ $1 -eq 0 || $2 -eq 0 ]]
then
echo "You didn't chose argument"
exit 1
elif
...
exit 0
在终端我试过了:
./Path/to/script argument1 argument2
结果我得到:
You chose argument1 and argument2
You didn't chose argument
我怎么可能在同一时刻返回正确的两个参数并将它们视为 0?
这里有什么问题?
【问题讨论】:
-
注意条件有点不稳定,最好用'&&'而不是'||'来表达。
-
您正在将字符串与数字进行比较。而是使用 if [[ -z $1 .. etc.
-
if (( $# < 2 )); then ...应该可以解决问题。