<分区>
我试图在脚本中测试 nginx 配置:
reply="$(nginx -t)"
echo $reply
但是 $reply 不包含返回的文本。如果我将第一行放在终端中,nginx 文本会在终端中弹出,但如果我将第二行放在终端中,则没有任何输出。 我的兴趣是在 if 语句中使用该 nginx 测试的输出
reply="$(nginx -t)"
if [[ ${reply} == *"nginx: configuration file /etc/nginx/nginx.conf test failed"* ]]
then
echo "It's there!";
fi
有什么方法可以获取变量中命令nginx -t返回的输出吗?