Shell——图形

目录

1、直线

2、空心矩形

3、直角三角形

4、倒直角三角形

5、直角三角形

6、可变大小菱形

7、直角梯形

 

 

 

 

1、直线

#!/bin/bash

for ((i=1; i<=20; i++))
do
    echo -n "*"
    if [ $i -eq 20 ];then
        echo ""
    fi
done

Shell——图形

 

 2、空心矩形

#!/bin/bash

for ((i=1; i<=10; i++))
do
        if [ $i -eq 1 -o $i -eq 10 ];then
                for ((j=1; j<=20; j++))
                do
                        echo -n "*"
                done
                echo ""
        else
                echo -n "*"
                for ((k=1; k<=18; k++))
                do
                        echo -n " "
                done
                echo "*"
        fi
done

Shell——图形

 

 3、直角三角形

#!/bin/bash


for ((i=1; i<=9; i++))
do
    for ((j=1; j<=$i; j++))
    do
        echo -n "*"
    done
    echo ""
done

Shell——图形

 

 4、倒直角三角形

#!/bin/bash

for ((i=1; i<=9; i++))
do
    for ((j=9; j>=i; j--))
    do
        echo -n "*"
    done
echo ""
done

Shell——图形

 

 5、直角三角形

#!/bin/bash

for ((i=1; i<=9; i++))
do
    for((j=9; j>=i; j--))
    do
        echo -n " "
    done
    for((k=1; k<=i; k++))
    do
        echo -n "*"
    done
echo ""
done

Shell——图形

 

 6、可变大小菱形

#!/bin/bash
read -p "请输入大小的数字:" n
for ((i=1; i<=$n; i++))
do
    for ((j=$n; j>=i; j--))
    do
        echo -n " "
    done
    for ((k=1; k<=$[$i*2 - 1]; k++))
    do
        echo -n "*"
    done
echo ""
done
for ((i=$[$n - 1]; i>=1; i--))
do
    for ((j=$n; j>=i; j--))
    do
        echo -n " "
    done
    for ((k=1; k<=$i; k++))
    do
        echo -n "*"
    done
    for ((g=2; g<=$i; g++))
    do
        echo -n "*"
    done
echo ""
done

Shell——图形

 

 7、直角梯形

#!/bin/bash

for ((i=1; i<=6; i++))
do
    for ((j=6; j>=i; j--))
    do
        echo -n " "
    done
    for ((k=1; k<=6; k++))
    do
        echo -n "*"
    done
    for ((g=1; g<=i; g++))
    do
        echo -n "*"
    done
echo ""
done

Shell——图形

 

上一篇:Linux - 流程控制语句


下一篇:shell基本操作(下)