效果如下图: 
#!/bin/bash#设置两个变量,i 和 j,一个代表行,一个代表列,国际象棋为 8*8 棋盘#i=1 是代表准备打印第一行棋盘,第 1 行棋盘有灰色和蓝色间隔输出,总共为 8 列#i=1,j=1 代表第 1 行的第 1 列;i=2,j=3 代表第 2 行的第 3 列#棋盘的规律是 i+j 如果是偶数,就打印蓝色色块,如果是奇数就打印灰色色块#使用 echo ‐ne 打印色块,并且打印完成色块后不自动换行,在同一行继续输出其他色块for i in {1..8}dofor j in {1..8}dosum=$[i+j]if [ $[sum%2] ‐eq 0 ];thenecho ‐ne "\033[46m \033[0m"elseecho ‐ne "\033[47m \033[0m"fidoneechodone
#!/bin/bash#set chess cell's widthread -p "Please set the chess cell's width( two space width as unit ):" widthif [[ $width =~ "^[0-9]+$" ]];thenecho "wrong width setting, check your input and try again."exitfilet width=$width*2#choose player's board cell colorplayer="player1"PS3="Which color do you want to set for $player :"select choice in red green yellow blue purple cyan white;docase $REPLY in[1-7])if [[ $player == player2 ]];thendeclare -i color2=$REPLYbreakelsedeclare -i color1=$REPLYfiplayer="player2"PS3="Which color do you want to set for $player :";;*);;esacdoneif (( color1==color2 ));thenecho "two player must choose different color, check your choice and try again."exitfi#print the chess boardfor (( i=0; i<4; i++ )); dofor (( j=0; j<$width/2; j++ ));dofor (( k=0; k<4; k++ ));doecho -e "\e[4${color1}m$(printf %${width}s)\e[0m\c"echo -e "\e[4${color2}m$(printf %${width}s)\e[0m\c"doneechodonefor (( j=0; j<$width/2; j++ ));dofor (( k=0; k<4; k++ ));doecho -e "\e[4${color2}m$(printf %${width}s)\e[0m\c"echo -e "\e[4${color1}m$(printf %${width}s)\e[0m\c"doneechodonedone
