我有这个脚本
#!/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
Run Code Online (Sandbox Code Playgroud)
它基本上检查参数3是A还是B,然后做回声.但它返回:
./test.sh: line 6: [A: command not found
./test.sh: line 8: [A: command not found
Run Code Online (Sandbox Code Playgroud)
我试图-eq用于比较,但它仍然无效.我该如何解决这个问题?
Fat*_*ror 32
我确信之前已经出现了,但是 - [实际上是一个命令.你需要一个空格[,以便shell找到它.