shell 脚本换行打印_如何用shell脚本实现打印国际象棋棋盘?

概述

今天主要分享一个有趣的shell脚本,实现打印国际象棋棋盘,主要看里面的逻辑是怎么实现的。


shell脚本

#!/bin/bash #set chess cell's widthread -p "Please set the chess cell's width( two space width as unit ):" widthif [[ $width =~ "^[0-9]+$" ]];then echo "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;do case $REPLY in [1-7]) if [[ $player == player2 ]];then declare -i color2=$REPLY break else declare -i color1=$REPLY fi player="player2" PS3="Which color do you want to set for $player :" ;; *) ;; esacdoneif (( color1==color2 ));then echo "two player must choose different color, check your choice and try again." exitfi #print the chess boardfor (( i=0; i<4; i++ )); do for (( j=0; j
1badef357a296c51e5164d84ec3da612.png
fdcc4eb9cf9ae2c0612983316e3ba073.png

实现效果:

931d1dd206c4d0b178ff8640315fff3c.png
c1fbecc5ddeb8a85fff1af8df51cf182.png

后面会分享更多devops和DBA方面内容,感兴趣的朋友可以关注下!

4e8953b22b7403d509361fea4c0af9e3.png
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值