gpt4 book ai didi

linux - bash脚本的格式

转载 作者:太空宇宙 更新时间:2023-11-04 09:43:43 25 4
gpt4 key购买 nike

我在运行这个 bash 脚本时遇到错误。我已经检查了所有手册,我觉得没问题?

感谢帮助。

  #!/bin/sh
HOME=/var/www
sleep 20
echo 'running' > $HOME/script-1-output.txt
if (-f $HOME/script-2-output.txt )
echo 'script-2 has run' >> $HOME/script-1-output.txt
else
echo 'script-2 has not run' >> $HOME/script-1-output.txt
fi
if (-f $HOME/script-3-output.txt)
echo 'script-3 has run' >> $HOME/script-1-output.txt
else
echo 'script-3 has not run' >> $HOME/script-1-output.txt
fi

最佳答案

在 bash 中,if 条件包含在 [] 而不是 () 之间。条件和方括号之间应该始终有空格。然后你需要使用 if-then-else-fi 语法。

if [ -f file.txt ]; then
echo "yes"
else
echo "no"
fi

关于linux - bash脚本的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18730368/

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