Monday, July 5, 2010

Draws chessboard on a maximised linux terminal using a bash script

Open a new terminal.

Save the following as a file "chessboard" -

vim chessboard 

and paste -

for (( i = 1; i <= 49 ; i++ )) ### Outer for loop ###
do
  for (( j = 1 ; j <= 49; j++ )) ### Inner for loop ###
  do
       tot=`expr $i + $j`
       tmp=`expr $tot % 2`
       if [ $tmp -eq 0 ]; then
           echo -e -n "\033[49m  "
       else
           echo -e -n "\033[40m  "
       fi
 done
echo -e -n "\033[49m" #### set back background colour to black
echo "" #### print the new line ###
done
echo -e -n "\033[49m \n" #### set back background colour to white

Make it executable -
chmod 755 chessboard

Run the script -
./chessboard

The terminal must be maximised.

Stare at the pattern for some time. Does it move ?

No comments:

OK GOOGLE on Samsung Galaxy S7 doesn’t work

To make Ok Google detection work on Galaxy S7 (Galaxy series phones) we need to perform a couple of steps. 1. As long as Samsung S vo...