gpt4 book ai didi

bash - Bash脚本: 'Syntax error: “fi” unexpected' within nested statement

转载 作者:行者123 更新时间:2023-12-03 08:01:37 24 4
gpt4 key购买 nike

我正在尝试编写脚本来切换HAproxy,以便在服务关闭时将用户重新路由到维护页面。这是我遇到的问题:

if [ "$idIsValid" = "false" ]; then
if [ "$(cat isUp)" = "true" ]; then
echo "Site is down! Routing to maintenance page."
echo false > isUp
mv haproxy.cfg haproxy.cfg.temp
mv haproxy.cfg.other haproxy.cfg
mv haproxy.cfg.temp haproxy.cfg.other

#restart haproxy
service haproxy restart
echo "Restarting HAproxy"

elif [ "$(cat isUp)" = "false" ]; then
#do nothing since it has already changed
echo "Nothing to do; service is still down."
else
#notify me that isUp is set to something other than true or false, or something else is wrong.
fi
fi

运行此命令时,出现错误:
status-check.sh: Syntax error: "fi" unexpected

此错误指向倒数第二行上的 嵌套fi 。我在这里找不到语法错误。请协助!谢谢。

最佳答案

这是因为最后一个else块中没有命令。如果删除该块或在其中放置命令(而不是注释),则不会出现语法错误。

关于bash - Bash脚本: 'Syntax error: “fi” unexpected' within nested statement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44783366/

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