以前在shell版區copy了段高手的代碼,顯示時間,
昨天拿來研究了會,改成function,以增強可閱讀性
#!/bin/bash
posx=$(stty size|cut -d' ' -f2)
posy=$(stty size|cut -d' ' -f1)
# Foregrand color
fblack=30
fred=31
fgreen=32
fyellow=33
fblue=34
fcyan=36 #青色
fwhite=37
# Background color
bblack=40
bred=41
bgreen=42
byellow=43
bblue=44
bcran=46
bwhite=47
function wprintf()
{
px=$1
py=$2
msg=$3
printf "\033[s\033[%s;%sH" $py $px #position x, y
printf "\033[0;%s;%sm%s\033[0m" $fred $byellow $msg
printf "\033[u" #end position
}
printf '\x1b[2J' #clear screen
while true
do
TM=$(date '+%T') ;
POSX=$((posx/2-3))
POSY=$((posy/2))
wprintf $POSX $POSY $TM
sleep .1
done
阅读(1697) | 评论(0) | 转发(0) |