gpt4 book ai didi

bash :如果 [ "echo test"== "test"];然后回显 "echo test outputs test on shell"fi;可能的?

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

bash 是否可以从 shell 执行命令,如果它返回某个值(或空值)则执行命令?

if [ "echo test" == "test"]; then
echo "echo test outputs test on shell"
fi

最佳答案

是的,您可以使用反引号或 $() 语法:

if [ $(echo test) = "test" ] ; then
echo "Got it"
fi

您应该将 $(echo test) 替换为

"`echo test`"

"$(echo test)"

如果您运行的命令的输出可以为空。

并且 POSIX“刺是相等的”test 运算符是 =

关于 bash :如果 [ "echo test"== "test"];然后回显 "echo test outputs test on shell"fi;可能的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8463145/

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