(9)作业
1、写个脚本,实现星三角
[root@centos6 scripts]# cat sanjiao.sh
#!/bin/bash
termCols=`tput cols`
maxLineNum=`seq 1 2 $termCols | wc -l`
echo "#当前终端的宽度最多能够正常打印$maxLineNum行"
read -p "#请输入要打印的三角形的行数,行数范围大于1小于等于$maxLineNum,请输入行数: " lineNeeds
[[ `tput cols` -ne $termCols ]] && echo "终端宽度已经被改变,请重新运行脚本" && exit
[[ $lineNeeds =~ ^[[:digit:]]+$ && $lineNeeds -ge 2 && $lineNeeds -le $maxLineNum ]]
[[ $? -ne 0 ]] && echo "输入值不合法" && exit
for line in `seq 1 $lineNeeds`;do
for ((kong=(lineNeeds-line);kong>0;kong--));do
echo -n " "
done
for((xing=1;xing<=(line*2-1);xing++));do
echo -n "*"
done
echo
done
[root@centos6 scripts]# bash sanjiao.sh
#当前终端的宽度最多能够正常打印79行
#请输入要打印的三角形的行数,行数范围大于1小于等于79,请输入行数: 5
*
***
*****
*******
*********
[root@centos6 scripts]#
2、用until循环实现国际象棋棋盘
[root@centos6 scripts]# cat xiangqi.sh
#!/bin/bash
#
#
#
i=1
until [ $i -gt 8 ];do
j=1
while [ $j -le 8 ];do
sum=`expr $i + $j`
z=`expr $sum % 2`
[ $z -eq 0 ] && echo -ne "\033[41;1m \033[0m"||echo -ne "\033[43;1m \033[0m"
let j++
done
echo
let i++
done
[root@centos6 scripts]#