shell图形化菜单界面

2/13/2017来源:经验技巧人气:880

如下写一个优雅的shell图形化界面

#!/bin/bash


# simple script menu
function diskspace {
        clear
        df -h
}
function whoSEOn {
    clear
    who
}
function memusage {
    clear
    cat /PRoc/meminfo
}
function menu {
    clear
    echo
    echo -e "\t\t\tSys Admin Menu\n"
    echo -e "\t1. Display disk space"
    echo -e "\t2. Display logged on users"
    echo -e "\t3. Display memory usage"
    echo -e "\t0. Exit program\n\n"
    echo -en "\t\tEnter option: "
    read -n 1 option
}
while [ 1 ]
do
    menu
    case $option in
        0)
        break ;;
        1)
        diskspace ;;
        2)
        whoseon ;;
        3)
        memusage ;;
        *)
        clear
        echo "Sorry, wrong selection";;
    esac
    echo -en "\n\n\t\t\tHit any key to continue"
    read -n 1 line
done
clear