Saturday, April 2, 2011

Create Chess Board Using Nested For loop in UNIX SHELL SCRIPT


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

output :~

4 comments:

  1. It was very nice article and it is very useful to Linux learners.We also provide Linux online training

    ReplyDelete
  2. It would be interesting if we can make the chessboard move on the screen

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. CASINO BETTING - 946 Central Ave, Las Vegas, NV 89109
    CASINO BETTING at 946 Central Ave in Las Vegas, 속초 출장샵 NV 89109. (702) 770-5580. Contact. Hours, Mon - Thu 9am - 9pm. 충청북도 출장안마 Contact details. 김해 출장샵 Hours. 남양주 출장마사지 Mon - 화성 출장마사지 Thu 11am - 3pm. Call (702) 770-7555.

    ReplyDelete