【发布时间】:2020-09-08 19:51:55
【问题描述】:
#!/bin/bash
whilenum=1
while [ $whilenum -lt 5 ]
do
if [ $whilenum == 1 ]
then
function funct1 {
echo The value of whilenum is $whilenum
}
funct1
else break
fi
if (( $whilenum == 2 | $whilenum == 3 ))
then
for animal in dog bird turtle
do
echo $animal
done
fi
if [ $whilenum == 4 ]
then
echo Enter your name
read username
fi
if [ ${#username} > 8 ]
then
echo User name is long
else
echo User name is short
fi
whilenum=$(( $whilenum+1 ))
done
当我调整数字以测试数字时,没有任何反应 我使while循环递增,因此它可以终止但不确定它是否工作。没有得到任何语法错误可能有一些逻辑错误
【问题讨论】:
标签: linux bash for-loop while-loop do-while