Problem Statement:
Print numeric value 0000-9999# use for loop
#!/bin/ksh
for i in {0..9999}
do
s=$(printf "%04d" $i)
echo "for $s times"
done
# use while loop
#!/bin/ksh
i=0
while [[ $i -le 9999 ]]
do
s=$(printf "%04d" $i)
echo "while $s times"
((i = i + 1))
done
本文介绍如何使用for循环和while循环在Shell脚本中打印从0000到9999的所有数值,并确保每个数值都以四位数的形式展示。
8434

被折叠的 条评论
为什么被折叠?



