gpt4 book ai didi

找不到 bash 输出命令

转载 作者:行者123 更新时间:2023-11-29 09:16:56 25 4
gpt4 key购买 nike

我面临以下问题,我已经创建了提到的条件,但是当我选择 y 表示是时,一切正常,但是当我选择 n 表示不是时,我得到恼人的错误输出:输出 :你同意 (y) 还是不同意 (n)n./myscript: [n: 找不到命令

myscript 是我的脚本的名字代码在这里:

echo  "Do you agree yes (y) or not (n)"
read answer
if ( [ "$answer" = 'y' ] || ["$answer" = 'Y' ]);
then

echo -e “ output for y”
done
else
echo -e " output for n "
exit 1;

知道如何摆脱输出并解决问题吗?谢谢

最佳答案

你错过了空间:

["$answer" = 'Y' ]

更改为:

[ "$answer" = 'Y' ]

脚本中还有其他错误。这里有工作代码:

echo  "Do you agree yes (y) or not (n)"
read answer
if ( [[ "$answer" = 'y' ]] || [[ "$answer" = 'Y' ]]);
then
echo -e " output for y"
else
echo -e " output for n"
exit 1
fi

关于找不到 bash 输出命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9831768/

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