linux shell 编写屏幕产生颜色的脚本学习笔记

效果图:在rhel5下显示
 
 
 
代码:
 
#!/bin/sh
tput init
MYDATE=`date +%D`
#---------function
function colour ()
{
  case $1 in
    black_green)
       echo "^[[40;32m"
       ;;
    black_yellow)
       echo "^[[40;33m"
       ;;
    black_white)
       echo "^[[40;37m"
       ;;
    black_cyan)
       echo "^[[40;36m"
       ;;
    black_red)
       echo "^[[40;31m"
       ;;
   esac
  
}
function xy ()
{
  _R=$1
  _C=$2
  _TEXT=$3
  tput  cup $_R $_C
  echo -n $_TEXT
}
function center ()
{
 _STR=$1
 _ROW=$2
 LEN=`echo $_STR | wc -c`
 COLS=`tput cols`
 HOLD_COL=`expr $COLS - $LEN`
 NEW_COL=`expr $HOLD_COL / 2`
 tput cup $_ROW $NEW_COL
 echo -n $_STR
}
#--------function end
tput clear
colour black_yellow
xy 2 3 "USER:$LOGNAME"
colour black_cyan
center "ADD A NEW WARP DRIVE TO A START SHIP" 3
echo -e "\f\f"
center "---------------------------------"  4
colour black_yellow
xy 5 1 "---------------------------------" 
xy 7 1 "---------------------------------"
xy 21 1 "---------------------------------"
center "Star Date $MYDATE"       22
xy 23 1 "---------------------------------"
colour black_green
xy 6 6 "Initials:"
read INIT
xy 8 14
echo -n "Security Code No:       :"
read CODE
xy 10 14
echo -n "Ship's Serial NO:       :"
read SERIAL
xy 12 14
echo -n "Is it on the Port Side:"
read PORT
colour black_red
center "Save This Record [Y..N]"  18
read ANS
colour black_white
--------------------------
说明:colour 函数控制颜色,其中 ^[  为控制字符,产生的方式,按<ctrl + v>,松开后,按ESC
            xy 函数  定位
            center 函数  居中显示
 
 

你可能感兴趣的:(linux,shell,职场,休闲,colour)