简单shell脚本编写(九九乘法表&国际棋盘&国旗)

标签: shell

使用简单shell编写打印九九乘法表

[[email protected] bin]#vim 99.sh
#!/bin/bash
for i in {1..9};do
    for j in {1..9};do
        if [ $j -le $i ];then
        echo -e "$j*$i=$[i*j]\t\c"
        fi
    done
    echo
done

结果如下图:

 

使用简单shell编写打印国际棋盘

 

#!/bin/bash
    
for i in {1..8};do
        temp1=$[ $i % 2 ]
    
        for j in {1..8};do
        temp2=$[ $j % 2 ]

        if [ $temp1 -eq  $temp2  ];then
                echo -e -n "\033[47m  \033[0m"
        else
                echo -e -n "\033[41m  \033[0m"
        fi

        done

        echo 
done

结果如下:

 打印国旗

#!/bin/bash

for i in {1..10}
do
	case $i in
		5)
			for j in {1..15}
			do
				case $j in
					5)
						echo -e "\033[33;41m☆ \033[0m\c"
						;;
					*)
						echo -e  "\033[41m  \033[0m\c"
				esac
			
			done
			;;
		2)
		for j in {1..15}
		do
				case $j in

					5)
						echo -e "\033[33;41m☆ \\033[0m\c"
						;;
					*)
						echo -e  "\033[41m  \033[0m\c"
				esac
		done
			;;
			
		3)
		for j in {1..15}
		do
				case $j in

					3)
						echo -e "\033[33;41m☆ \033[0m\c"
						;;	

					6)
						echo -e "\033[33;41m☆ \033[0m\c"
						;;
					*)
						echo -e  "\033[41m  \033[0m\c"
				esac
		done
			;;
		4)
		for j in {1..15}
		do
				case $j in
					6)
						echo -e "\033[33;41m☆ \033[0m\c"
						;;

					*)
						echo -e  "\033[41m  \033[0m\c"
				esac
		done
			;;
		*)

				for j in {1..15}
		do
			echo -e  "\033[41m  \033[0m\c"
		done
	esac
	echo
done

结果如下:

 

原文链接:加载失败,请重新获取