昨天看LFS启动脚本时想到的。
Linux启动时会在每一行信息后都输出一个"[ OK ]"、"[ WARN ]"或"[ FAIL ]",这种输出方式在LFS启动脚本的function中可以得到解答:#!/bin/bash
# output just like linux-bootup message ".... [ OK ]"
## Screen Dimensions
# Find current screen size
if [ -z "${COLUMNS}" ]; then
COLUMNS=$(stty size)
COLUMNS=${COLUMNS##* }
fi
# When using remote connections, such as a serial port, stty size returns 0
if [ "${COLUMNS}" = "0" ]; then
COLUMNS=80
fi
## Measurements for positioning result messages
COL=$((${COLUMNS} - 8))
WCOL=$((${COL} - 2))
## Set Cursor Position Commands, used via echo -e
SET_COL="\\033[${COL}G" # at the $COL char
SET_WCOL="\\033[${WCOL}G" # at the $WCOL char
CURS_UP="\\033[1A\\033[0G" # Up one line, at the 0'th char
## Set color commands, used via echo -e
# Please consult `man console_codes for more information
# under the "ECMA-48 Set Graphics Rendition" section
#
# Warning: when switching from a 8bit to a 9bit font,
# the linux console will reinterpret the bold (1;) to
# the top 256 glyphs of the 9bit font. This does
# not affect framebuffer consoles
NORMAL="\\033[0;39m" # Standard console grey
SUCCESS="\\033[1;32m" # Success is green
WARNING="\\033[1;33m" # Warnings are yellow
FAILURE="\\033[1;31m" # Failures are red
INFO="\\033[1;36m" # Information is light cyan
BRACKET="\\033[1;34m" # Brackets are blue
STRING_LENGTH="0" # the length of the current message
echo -n -e "test test test .............. 11111"
echo -n " ||| now the fkjsal;kfa"
echo -e "${SET_COL}""${BRACKET}""[""${SUCCESS}"" OK ""${BRACKET}""]""${NORMAL}"
echo -n -e "test est esttt esttt ------------ 2222"
echo -e "${SET_COL}""${BRACKET}""[""${FAILURE}"" FAIL ""${BRACKET}""]""${NORMAL}"
echo -n -e "test ewa tasfj a;ksljet;a ljkeakl;j"
echo -e "${SET_COL}""${BRACKET}""[""${WARNING}"" WARN ""${BRACKET}""]""${NORMAL}"
另外,以前看到过的一个旋转的棍子表示进度的,用这种方式:#!/bin/bash
# a rout-line
if [ -z "${COLUMNS}" ]; then
COLUMNS=$(stty size)
COLUMNS=${COLUMNS##* }
fi
if [ "${COLUMNS}" = "0" ]; then
COLUMNS=80
fi
COL=$((${COLUMNS} - 20))
SET_COL="\\033[${COL}G" # at the $COL char
echo -n "asfdl;adfd;jja;:"
let n=0
while test $n -lt 5000 ; do
let n=`expr $n+1` # 这主要还起延时的作用,要不用`let n++`就行了
echo -en "${SET_COL}/"
let n=`expr $n+1`
echo -en "${SET_COL}|"
let n=`expr $n+1`
echo -en "${SET_COL}\\"
let n=`expr $n+1`
echo -en "${SET_COL}-"
done
echo -e "${SET_COL}[ OK ]"
//EOF
2007-01-21
some messages echo
Posted by Davy Hawk at 1/21/2007 12:51:00 PM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment