【发布时间】:2012-02-15 14:36:43
【问题描述】:
我有这个脚本
#!/bin/sh
if [ $# -ne 3 ] ; then
echo "param 1, param2, and A or B "
exit 1;
elif [ $# -eq 3 ]; then
if [$3 = "A"] ; then
echo "A"
elif [$3 = "B"]; then
echo "B"
fi
fi
它基本上是检查参数 3 是 A 还是 B,然后做 echo。但它返回:
./test.sh: line 6: [A: command not found
./test.sh: line 8: [A: command not found
我尝试使用-eq 进行比较,但还是不行。我该如何解决这个问题?
【问题讨论】:
-
您不需要
elif [ $# -eq 3 ]; then行,因为您知道$#在您的第一次测试中为 3。然后,您可以避免一级缩进和fi将if [$3 = "A"] ; then替换为elif [$3 = "A"] ; then。
标签: shell