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
本文介绍如何使用两种不同的Linux脚本方法打印阶乘数,包括while循环和for循环的实现方式。提供了具体的bash脚本示例,展示了如何通过手动输入参数来执行脚本并打印从1到指定数字的所有整数。
1333

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



