当前位置: 技术问答>linux和unix
Shell编程:怎么实现从1到100的输出?
来源: 互联网 发布时间:2015-08-27
本文导语: 不知道如何实现变量的自加,如果有代码更好 | You can write a shell file count.sh like this: ***************************** #!/bin/sh num=1 while [ $num -le $1 ] do echo $num num=`expr $nu...
不知道如何实现变量的自加,如果有代码更好
|
You can write a shell file count.sh like this:
*****************************
#!/bin/sh
num=1
while [ $num -le $1 ]
do
echo $num
num=`expr $num + 1`
done
num=1
while [ $num -le $1 ]
do
echo $num
num=`expr $num + 1`
done
*****************************
$chmod a+rwx count.sh
Then you can run ./count.sh count_num
example: ./count.sh 100
programme will input the number 1~100
good luck!
*****************************
#!/bin/sh
num=1
while [ $num -le $1 ]
do
echo $num
num=`expr $num + 1`
done
num=1
while [ $num -le $1 ]
do
echo $num
num=`expr $num + 1`
done
*****************************
$chmod a+rwx count.sh
Then you can run ./count.sh count_num
example: ./count.sh 100
programme will input the number 1~100
good luck!
|
#!/bin/sh
num=1
while [ $num -le $1 ]
do
echo $num
num=`expr $num + 1`
done
num=1
while [ $num -le $1 ]
do
echo $num
num=`expr $num + 1`
done
|
可以使用类似于C的语法
#!/bin/sh
for ((a=1; a
#!/bin/sh
for ((a=1; a