我是bash编程的新手,正在尝试编写脚本。到目前为止,这是非常基本的,但是最后我得到了上面的错误done
。
for ((i = 1; i < 13; i++)) do
if [ "$i" -lt "4" ]; then
touch Block1/B8IT11"$i".txt
echo B8IT11"$i" created
else if [ "$i" -gt "3" -a "$i" -lt "7" ]; then
touch Block2/B8IT11"$i".txt
echo B8IT11"$i" created
else if [ "$i" -lt "6" -a "$i" -lt "10" ]; then
touch Block3/B8IT11"$i".txt
echo B8IT11"$i" created
else
touch Block4/B8IT11"$i".txt
echo B8IT11"$i" created
fi
done
在我看来,我看不到问题,因为if-else if-else
结尾为fi
,for
循环应以结尾done
。
我已经做到了cat -v
,甚至dos2unix
做到了。有人看到我想念的东西吗?
else if
bash中没有。您所拥有的是else
一个(嵌套的)if
构造。外部else
未终止(缺少fi
)。Bash认为您仍处在else
障碍之中,所以现在还没想到done
:
for ((i = 1; i < 13; i++)) do
if [ "$i" -lt "4" ]; then
touch Block1/B8IT11"$i".txt
echo B8IT11"$i" created
else
if [ "$i" -gt "3" -a "$i" -lt "7" ]; then
touch Block2/B8IT11"$i".txt
echo B8IT11"$i" created
else
if [ "$i" -lt "6" -a "$i" -lt "10" ]; then
touch Block3/B8IT11"$i".txt
echo B8IT11"$i" created
else
touch Block4/B8IT11"$i".txt
echo B8IT11"$i" created
fi
done
修复:将所有更改else if
为elif
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句