1.猜数字
#!/bin/bash
x=$[RANDOM%10+1]
while read -p "please your number1-10:" num;do
#echo $num
if [ "$num" -eq "$x" ];then
echo your gueess right.
break
elif [ "$num" -lt "$x" ];then
echo letter
else
echo more
fi
done
2.棋盘
#!/binbash
red="\033[41m"
blue="\033[44m"
cloend="\033[0m"
#echo -e "$red $cloend"
for j in {1..8};do
if [ $[j%2] -eq 1 ];then
for i in {1..8};do
if [ $[i%2] -eq 1 ];then
echo -e "$red $cloend\c"
else
echo -e "$blue $cloend\c"
fi
done
elif [ $[j%2] -eq 0 ];then
for k in {1..8};do
if [ $[k%2] -eq 0 ];then
echo -e "$red $cloend\c"
else
echo -e "$blue $cloend\c"
fi
done
fi
echo
done
3.九九乘法表
#!/bin/bash
for i in {1..9};do
for j in $(seq $i);do
let k=i*j
echo -e "$i x $j = $k\t\c"
#echo -e "${j}x$i=$[j*i]\t\c"
done
echo
done
4.echo yes or no
#!/bin/bash
read -p "Input yes or no: " yn
[[ "$yn" =~ ^[yY]([Ee][Ss])?$ ]] && { echo yes;exit 0; }
[[ "$yn" =~ ^[Nn][Oo]?$ ]] && { echo no;exit 1; }
echo please input yes or no.
来源:CSDN
作者:从小打酱油
链接:https://blog.csdn.net/apple2417/article/details/104087633