linux chess board script .md (including script comments, see more intuitive)
final effect:
Topic : scripting, to achieve print chess board
Path :( only Author) PDF: D: \ Download_SD- Date and Bak (D disk download) \ learning materials \ pdf file \ basics \ 15SHELL advanced scripting .pdf
15SHELL Advanced Scripting .pdf
5, scripting, to achieve print chess board
Video :( only Author) 17, 18 days
See :( logic code comments)
1 cycle [for done] lattice depth.
2, the second layer is simplified nested loop [for done].
3, the command is determined [if else] reference, to achieve the first and second rows alternating grid
Outline summary :() ------- first stage (row) >>> loop (columns) two cycles of the second stage of the cycle comprises >>> (if else) Analyzing two two cycles
View Script command :()
[root@c7_uscwifi_cn ~]# cat chess.sh
cat chess.sh
Script Content:
#!/bin/bash
#
#********************************************************************
#Author: quansen
#QQ: 1955346284
#Date: 2019-08-25
#FileName: chess.sh 国际象棋
#URL: http://www.uscwifi.cn
#Description: The test script
#Copyright (C): 2019 All rights reserved
#********************************************************************
#背景为 浅色 的空格 *2
YELLO_BACKGROUND_SPACE_x2='\033[0;43m \033[0m'
#背景为 绿色 的空格 *2
GREEN_BACKGROUND_SPACE_x2='\033[0;42m \033[0m'
#简化变量名
Y_BG_S_x_0=${YELLO_BACKGROUND_SPACE_x2}
G_BG_S_x_0=${GREEN_BACKGROUND_SPACE_x2}
#第一层for 循环 8次 $i(行);做
for i in {1..8};do
#如果 $i 行数为奇数(除以二,余数为1);就
if [ $[${i}%2] -eq 1 ];then
{
#第二层循环1 $j(列) 4列;做
for j in {1..4};do
#打印变量 浅色空格X2
echo -en "${Y_BG_S_x_0}"
#打印变量 绿色空格X2
echo -en "${G_BG_S_x_0}"
done
}
#如果不是(if判断),那么 (如果不是奇数 ,是偶数,那么)
else
{ #第二层循环2 循环循环 $j(列) 4列;做
for j in {1..4};do
#打印变量 绿色空格X2
echo -en "${G_BG_S_x_0}"
#打印变量 浅色空格X2
echo -en "${Y_BG_S_x_0}"
done
}
fi
echo
done
#打印作者 联系方式
echo -e "
#*******************************#
# #
#Author: *#
# \033[1;32mquansen\033[0m #*
# *#
#QQ: 599503255;\033[1;32m1955346284\033[0m #*
# #
#*******************************#
"