apt-get install fortune cowsay cconv
1. 程式碼 Cowsay.sh
#!/usr/bin/env bash
PATH=$PATH
SLEEP=6
declare -A CS
MAXEM=0
for e in `ls /usr/share/cowsay/cows/*.cow | sed 's/\.cow//' | awk 'BEGIN{FS="/"};{print $NF}'`
do
CS[$MAXEM]="$e"
MAXEM=$((MAXEM+1))
done
while [ 1 ];
do
clear
S=$(( RANDOM % 52 ))
S=$((S+SLEEP))
F="$S"
FACE=""
if [ $F -gt $MAXEM ]; then
F=$(( F % MAXEM ))
FACE=${CS[$F]}
else
FACE=${CS[$F]}
fi
date +"%Y/%m/%d %H:%M:%S"
/usr/games/fortune | cconv -f UTF8-CN -t UTF8-TW | sed -r "s/\x1B\[[0-9;]*[mK]//g" | /usr/games/cowsay -f $FACE
sleep $S
done
2. 執行
chmod a+x Cowsay.sh
./Cowsay.sh
或
bash Cowsay.sh
No comments:
Post a Comment