Weltraumrennen in Bash

From S23Wiki
Jump to: navigation, search
#!/bin/bash
# "Weltraumrennen" in Bash - Linux Magazin 03/11 Listing 2 - S.113
pos=40
width=80

while true; do
read -t1 -s -n1 x
case "$x" in
        g) pos=$(($pos - 1)) ;;
        h) pos=$(($pos +1 ));
esac

for ((i=0; i < $width; i++))
do
        if [ $i -eq $pos ]; then
        echo -n 'V'
        elif [ $(($RANDOM % 9)) -eq 0 ]; then
        echo -n '*'
        else
        echo -n ' '
        fi
done

echo
done