写一个shell脚本。提示你输入一个暂停的数字,然后从1打印到该数字。然后询问是否继续。继续的话在输入个在数字接着打印。不继续退出。
例:如果输入的是5,打印1 2 3 4 5 然后继续 输入15 然后打印 6 7 ...14 15 依此类推。
#!/bin/bash
#Printing numbers
#Written by Adai
read -p "Please input a number as the range of print:" m
m1=`echo $m |sed 's/[0-9]//g'`
if [ -z $m1 ]
then
for i in `seq 1 $m`
do
echo "$i"
done
else
echo "It's not a number!"
exit
fi
while :
do
read -p "Input a number greater than the last one to continue,others to quit:" n
n1=`echo $n |sed 's/[0-9]//g'`
k=$[$m+1]
if [ -z "$n1" ] && [ $n -gt $m ]
then
for c in `seq $k $n`
do
echo "$c"
m=$c
done
else
exit
fi
done
通过数学计算:
#!/bin/bash
### shell习题 09-19
tag=0
while :
do
read -p "请输入一个数值:" n1
[ -z “$n1” ] && echo "没有输入数值。" && break
[ "$n1" == "q" ] && exit
if [ $n1 -gt $tag ];then
for ((i=$tag;i
tag=$[$tag + 1 ]
echo $tag
done
else
for ((i=$tag;i>$n1;i-- ));do
tag=$[$tag - 1 ]
echo $tag
done
fi
done
铭哥:
#!/bin/bash
read -p "请输入您想要暂停的数字:" number_1
for i in `seq 1 $number_1`;
do
echo $i
done
read -p "是否继续输入数字?" a
if [ $a == "yes" ];then
read -p "请继续输入您想要暂停的数字:" number_2
number_3=$[$number_1+1]
if [ $number_2 -gt $number_1 ];then
for h in `seq $number_3 $number_2`;
do
echo $h
done
else
echo "输入数字错误,请输入大于的数字!"
fi
else
exit
fi