Pyramid

Below are the steps to draw pyramid on terminal

1- Create a file name pyramid1.sh and write below code in.

#!/bin/bash
# Author : LEOxian 
# License: GPLv2
# Description: Pyramid
# Date : 20-March-2012
 
clear
col=20
for ((i=1;i<=10;i++))
do
  row=$[$i + 2] 
  ((col--))
  tput cup $row $col
  max=$[$j + 1] 
  for ((j=1;j<=max;j++)) 
    do  
      echo -n "*" 
    done
done
tput cup $[ $row + 1 ] $col
echo -e "Hope you liked it!\n"

2- Save the code in file.

3- Set executable permission – “chmod   a+x   pyramid1.sh .

4- Run script like  ./pyramid1.sh  which will draw pyramid on terminal.

Note: Run script on terminal with white background.

Output-

Below are the steps to draw pyramid on terminal

1- Create a file name pyramid2.sh and write below code in.

#!/bin/bash
# Author : LEOxian 
# License: GPLv2
# Description: Pyramid
# Date : 20-March-2012

clear
MAX_NO=9
for ((i=1;i<=$MAX_NO;i++))
  do
    rowno=$(expr $i + $MAX_NO)
    colno=$(expr 15 + $i - $MAX_NO)
    tput cup $rowno $colno
    valno=$(expr $MAX_NO - $i)
    for ((j=1;j<=$valno;j++))
      do
        echo -n " *" 
      done
    echo ""
  done
echo -e "\n\t Hope you liked it!\n"

2- Save the code in file.

3- Set executable permission – “chmod   a+x   pyramid2.sh .

4- Run script like  ./pyramid2.sh  which will draw pyramid on terminal.

Note: Run script on terminal with white background.

Output-

Leave a Reply

Your email address will not be published. Required fields are marked *