[英]How to fix my bash script from error: syntax error near unexpected token `done'?
I am trying to run this bash program in a Centos7 machine.我试图在 Centos7 机器上运行这个 bash 程序。 I have tried many different ways but all the time I get this error:
我尝试了很多不同的方法,但总是出现此错误:
line 31: syntax error near unexpected token `done' line 31: `done'
Line 31 belongs to the first done
.第 31 行属于第一个
done
。
I did cat -v mybash.bash
to check for weird tokens and there are none.我做了
cat -v mybash.bash
来检查奇怪的标记,但没有。
My script is as follows:我的脚本如下:
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
Please help me notice what I am doing wrong.请帮助我注意我做错了什么。
My guess is that the slurm submission script is not there.我的猜测是 slurm 提交脚本不存在。 The following checks that one and no more than one script is found.
以下检查是否找到一个且不超过一个脚本。
I also moved the cd..
to happen only after a cd
.我还移动了
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.