An Intresting Shell Script

Sunday 13 November 2011 | posted in , | 0 comments

A Shell Script to print the Chess pattern on the terminal.


  • $ vi chessboard

  • for (( i = 1; i <= 9; i++ )) ### Outer for loop ###

  • do

  • for (( j = 1 ; j <= 9; j++ )) ### Inner for loop ###

  • do

  • tot=`expr $i + $j`

  • tmp=`expr $tot % 2`

  • if [ $tmp -eq 0 ]; then

  • echo -e -n "\033[47m "

  • else

  • echo -e -n "\033[40m "

  • fi

  • done

  • echo -e -n "\033[40m" #### set back background colour to black

  • echo "" #### print the new line ###

  • done


 

Run the above script as follows:

$ chmod +x chessboard

$ ./chessboard

 

 

OUTPUT:



 

 

Print
0 Responses So far

Post a Comment