【linux】使用shell脚本打印阶乘数

Linux脚本打印阶乘数


需求:
1.打印阶乘数,如:1 2 3 4 5 ......
2.手动传入值
方法1(while):

#! /bin/bash

a=1
while test $a -le $1;do
        echo $a;((a++));done


方法2(for):
(1)

#! /bin/bash

for ((a=1;a<=$1,a++));do echo $a;done

(2)

#! /bin/bash

for i in $(seq 1 $1);do echo $i;((i++));done

注:
执行方式
sh test.sh 5

./test.sh 5

例如:
./test.sh 5
1
2
3
4
5