语法错误接近意外的令牌完成 bash 脚本



我是 Bash 脚本的新手,我在意外的令牌done附近收到此语法错误。谁能帮我。提前谢谢。

#!/bin/bash -x
echo "starting the process"
while true
do
echo "Fetching environment variables"
envsubst < /opt/config.conf.template > /opt/config.conf.prod
if [ -f /opt/config.conf.prod ] 
then
echo "Config file exists."
python /opt/Deon.py /opt/config.conf.prod
fi
done

脚本中有 Windows 行结尾。在它上运行dos2unix,它会起作用。正如其他评论者所说,您还需要检查Notepad++是否设置为对Bash脚本使用Unix行尾。

试试这个:

#!/bin/bash -x
echo "starting the process"
while true; do
echo "Fetching environment variables"
envsubst < /opt/config.conf.template > /opt/config.conf.prod
if [ -f /opt/config.conf.prod ]; then
echo "Config file exists."
python /opt/Deon.py /opt/config.conf.prod
fi
done

不确定是否需要,但我通常将 do 放在与我的条件相同的行上,并在两者之间放置一个分号(与 if 语句相同(。我尝试以这种方式运行,它似乎工作正常,所以我相当确定这就是问题所在,如果我错了,请随时纠正我。

最新更新