gpt4 book ai didi

shell - 比较字符串时找不到命令

转载 作者:行者123 更新时间:2023-12-04 11:17:19 24 4
gpt4 key购买 nike

我有这个脚本

#!/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进行比较,但它仍然不起作用。我该如何解决这个问题?

最佳答案

我确定这之前已经出现过,但是 -- [实际上是一个命令。您需要在 [ 后面留一个空格为了让 shell 找到它。

关于shell - 比较字符串时找不到命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9295307/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com