typora/note/Shell/嵌套循环.md

43 lines
414 B
Markdown
Raw Permalink Normal View History

2024-12-11 21:48:55 -05:00
```
#! /bin/env bash
read -p "input a number:" num
for ((i=1;i<=$num;i++))
do
for ((j=1;j<=i;j++))
do
echo -n $j
done
echo
done
for ((i=1;i<=$num;i++))
do
str=""
for ((j=1;j<=i;j++))
do
str=$str$j
done
echo $str
done
```
```
me@me-EQ59:~/shell_demo/scripts/shell02$ ./print-1-5.sh
input a number:6
1
12
123
1234
12345
123456
1
12
123
1234
12345
123456
me@me-EQ59:~/shell_demo/scripts/shell02$
```