欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-03-19 13:21:46
...

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

[aaa@qq.com 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脚本编写(九九乘法表&国际棋盘&国旗)

 

使用简单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

结果如下:

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

 打印国旗

#!/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

结果如下:

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

相关标签: shell