Bash SHELL, Chess Board Printing


Shell Script Programming is of lots of fun. The following script prints a chess board with 8×8 squares interleaving black and white. Using simple loops tex_8fb1f5024a605dc7737c61a8a376e067 Bash SHELL, Chess Board Printing algorithms BASH batch script beginner brute force implementation non-technical programming languages tools / utilities tricks and some simple math yields the chess board printing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/sh
# https://helloacm.com
 
for i in $(seq 1 8)
do
    for j in $(seq 1 8)
    do
        S=$(((i+j)%2))
        if [ $S -eq 0 ]
        then
            echo -n "\033[47m " # white
        else
            echo -n "\033[40m " # black
        fi
    done
    echo -n "\033[40m" # black, ensure it exists normally
    echo "" # new line
done
#!/bin/sh
# https://helloacm.com

for i in $(seq 1 8)
do
	for j in $(seq 1 8)
	do
		S=$(((i+j)%2))
		if [ $S -eq 0 ]
		then
			echo -n "\033[47m " # white
		else
			echo -n "\033[40m " # black
		fi
	done
	echo -n "\033[40m" # black, ensure it exists normally
	echo "" # new line
done

This will print the following roughly. Please note that printing the black and white squares using echo command should take the special characters. The looping in BASH Shell can be reviewed at [here].

chess Bash SHELL, Chess Board Printing algorithms BASH batch script beginner brute force implementation non-technical programming languages tools / utilities tricks

In [here], the script has been converted to Windows Batch.

BASH Programming/Shell

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
257 words
Last Post: 301 and 302 Redirects
Next Post: Large Address Aware

The Permanent URL is: Bash SHELL, Chess Board Printing

Leave a Reply