* Advanced shell base of the pyramid

1. First we print right triangle

  . 1 ! # / Bin / the bash
   2  
  . 3 Read -p " input pyramid layers: " Line
   . 4  
  . 5  for ((I = . 1 ; I <= Line; I ++ ))
   . 6  do 
  . 7          for ((J = . 1 ; J <= I; J ++ ))
   . 8          do 
  . 9                  echo -n " * " 
 10          DONE 
 . 11          echo 
 12 is  DONE
. [root @ Logan Day3] # bash JZT SH  
enter the pyramid layers: 5
 
* 
** 
*** 
**** 
*****

 2. Pyramid

  . 1 ! # / Bin / the bash
   2  
  . 3 Read -p " input pyramid layers: " Line
   . 4  for ((I = . 1 ; I <= Line; I ++ ))
   . 5  do 
  . 6          for ((K = . 1 ; K <= Line -i; ++ K ))
   . 7          do 
  . 8                  echo -n "  " 
  . 9          DONE 
 10          for ((J = . 1 ; J <= 2 * I- . 1 ; J ++ ))
  . 11          do 
 12 is                  echo -n " * " 
 13 is         done
 14         echo
 15 done
Enter the pyramid layers: 5 
    * 
   *** 
  ***** 
 ******* 
*********

3. hollow pyramid

1 #!/bin/bash
  2 
  3 read -p "输入金字塔层数: " line
  4 for((i=1;i<=line;i++))
  5 do
  6         for((k=1;k<=line-i;k++))
  7         do
  8                 echo -n " "
  9         done
 10         for((j=1;j<=2*i-1;j++))
 11         do
 12                 if [ $i -eq 1 -o $i -eq $line ]
 13                 then
 14                         echo -n "*"
 15                 else
 16                         if [ $j -eq 1 -o $j -eq $((2*$i-1)) ]
 17                         then
 18                                 echo -n "*"
 19                         else
 20                                 echo -n " "
 21                 fi
 22         fi
 23         done
 24         echo
 25 done
输入金字塔层数: 5
    *
   * *
  *   *
 *     *
*********

 

Guess you like

Origin www.cnblogs.com/MR-ws/p/11110717.html