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

 

 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

 

 3、直角三角形

#!/bin/bash


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

 

 4、倒直角三角形

#!/bin/bash

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

 

 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

 

 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

 

 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

 

posted @ 2021-07-26 12:22  peiqy  阅读(65)  评论(0编辑  收藏  举报