shell屏幕菜单脚本附演示效果

发布时间:2020-06-26编辑:脚本学堂
分享一例shell屏幕菜单脚本,shell菜单效果的实例代码,需要的朋友参考下。

例子,shell屏幕菜单的实现代码。
 

复制代码 代码示例:

#!/bin/sh
#menu

tput init
MYDATE=`date +%D`
colour()
{
    case $1 in
    balck_green)
        echo ''
        ;;
    black_yellow)
        echo ''
        ;;
    black_white)
        echo ''
        ;;
    black_cyan)
        echo ''
        ;;
    black_red)
        echo ''
        ;;
    esac
}
 
xy()
{
    #_R=row, _C=colnum
    _R=$1
    _C=$2
    _TEXT=$3
    tput cup $_R $_C
    echo -n $_TEXT
}
 
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
}
 
tput clear
colour red_yellow
xy 2 3 "USER: $LOGNAME"
colour balck_cyan
center "ADD A NEW WARP DRIVE TO A STAR SHIP" 3
echo -e "ff"
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 red_yellow
center "Save This Record [Y..N]: " 18
read ans
colour black_white

shell菜单效果如图:
shell屏幕菜单<a href=http://www.jb200.com/jb/ target=_blank class=infotextkey>脚本</a>