[英]How to fix my bash script from error: syntax error near unexpected token `done'?
我试图在 Centos7 机器上运行这个 bash 程序。 我尝试了很多不同的方法,但总是出现此错误:
line 31: syntax error near unexpected token `done' line 31: `done'
第 31 行属于第一个done
。
我做了cat -v mybash.bash
来检查奇怪的标记,但没有。
我的脚本如下:
for mainFolder in *
do
if [ -d "${mainFolder}" ]
then
cd "${mainFolder}" || exit
echo "Entering in directory ${mainFolder}"
cp ../mypy.py .
chmod +x mypy.py
./mypy.py
echo "Executing mypy.py"
sleep 1
for subFolder in *
do
if [ -d "${subFolder}" ]
then
cd "${subFolder}" || exit
echo "Entering in directory $subFolder in $mainFolder"
echo "Submitting slurm file in current directory"
sbatch *.slurm
sleep 1
fi
cd ..
done
fi
cd ..
done
请帮助我注意我做错了什么。
我的猜测是 slurm 提交脚本不存在。 以下检查是否找到一个且不超过一个脚本。
我还移动了cd..
仅在cd
之后发生。
for mainFolder in *
do
if [ -d "${mainFolder}" ]
then
echo "Entering in directory ${mainFolder}"
cd "${mainFolder}" || exit
cp ../mypy.py .
chmod +x mypy.py
echo "Executing mypy.py"
./mypy.py
sleep 1
for subFolder in *
do
if [ -d "${subFolder}" ]
then
cd "${subFolder}" || exit
echo "Entering in directory $subFolder in $mainFolder"
scripts=$(ls *.slurm)
nScripts=$(echo $scripts | wc -w)
if [ $nScripts == 1 ]
then
echo "Submitting $scripts"
sbatch $scripts
elif [ $nScripts == 0 ]
then
echo "Error: No script found"
else
echo "Error: $nScripts scripts found (${scripts})"
fi
sleep 1
cd ..
fi
done
cd ..
fi
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.