美文网首页Shell
shell打印图形

shell打印图形

作者: 小短腿电工 | 来源:发表于2018-12-09 23:24 被阅读48次

    闲来无事来一发,你皮任你皮。

    #!/bin/bash
    echo -e "输入1打印三角形\n输入2打印矩形\n输入3打印棱形\n输入4退出脚本"
    PS3="请输入对应的序号:"
    read -p "请输入几层图形:" n
    select input in 1 2 3 4 ;do
     case $input in
            1)
    echo "三角形"
    for i in `seq 1 $n`
    do
      for m in `seq $[$n-$i]`
      do
            echo -n " "
      done 
      for j in `seq $i`
      do
            echo -n "*  "
      done
      echo  
    done
            ;;
            2)
      echo "矩形"
    for i in `seq 1 $n`
    do
      for m in `seq $n`
      do
      echo -n "*    "
      done
      echo ""       
    done
            ;;
            3)
      echo "棱形"
    for (( i=1;i<10;i++ ))
    do
     if [ $i -le 5 ];then
            for (( s=$((10-i));s>i;s-- ))
            do
            echo -n "-"
            done
            for ((m = 1; m <= $((2*i-1)); m++))
            do
    #!/bin/bash
    echo -e "输入1打印三角形\n输入2打印矩形\n输入3打印棱形\n输入4退出脚本"
    PS3="请输入对应的序号:"
    read -p "请输入几层图形:" n
    select input in 1 2 3 4 ;do
     case $input in
            1)
    echo "三角形"
    for i in `seq 1 $n`
    do
      for m in `seq $[$n-$i]`
      do
            echo -n " "
      done
      for j in `seq $i`
      do
            echo -n "*  "
      done
      echo  
    done
            ;;
            2)
      echo "矩形"
    for i in `seq 1 $n`
    do
      for m in `seq $n`
      do
      echo -n "*    "
      done
      echo ""       
    done
            ;;
            3)
      echo "棱形"
    for (( i=1;i<10;i++ ))
    do
     if [ $i -le 5 ];then
            for (( s=$((10-i));s>i;s-- ))
            do
            echo -n "-"
            done
            for ((m = 1; m <= $((2*i-1)); m++))
            do
            echo -n "* "
            done
            echo ""
     elif [[ $i -gt 5 ]] ;then
            n=$((10-i))
            for ((j=$((10-n));j>n;j--));do
            echo -n "-" 
            done
            for ((m = 1; m <= $((2*n-1)); m++))
            do
            echo -n "* "
            done
            echo "" 
    fi
    done
            ;;
            4)
            echo $0
            exit 1
     esac
    done
    

    效果展示

    [root@bogon sbin]# sh san.sh 
    输入1打印三角形
    输入2打印矩形
    输入3打印棱形
    输入4退出脚本
    请输入几层图形:5
    1) 1
    2) 2
    3) 3
    4) 4
    请输入对应的序号1
    三角形
        *  
       *  *  
      *  *  *  
     *  *  *  *  
    *  *  *  *  *  
    请输入对应的序号2
    矩形
    *    *    *    *    *    
    *    *    *    *    *    
    *    *    *    *    *    
    *    *    *    *    *    
    *    *    *    *    *    
    请输入对应的序号3
    棱形
    --------* 
    ------* * * 
    ----* * * * * 
    --* * * * * * * 
    * * * * * * * * * 
    --* * * * * * * 
    ----* * * * * 
    ------* * * 
    --------* 
    请输入对应的序号4
    san.sh
    

    相关文章

      网友评论

        本文标题:shell打印图形

        本文链接:https://www.haomeiwen.com/subject/kaokhqtx.html