菜单栏

方法一:

关键词:echo -e

#!/bin/bash 
# simple script menu 
function diskspace { 
 clear 
 df -k 
} 
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

实现效果:

菜单栏

方法二:

关键词:

select option in

#!/bin/bash 
# using select in the menu 
function diskspace {
 clear
 df -k
}
function whoseon {
 clear
 who
}
function memusage {
 clear
 cat /proc/meminfo
}
PS3="Enter option: "
select option in "Display disk space" "Display logged on users" "Display memory usage" "Exit program"
do
 case $option in
 "Exit program")
 break ;;
 "Display disk space")
 diskspace ;;
 "Display logged on users")
 whoseon ;;
 "Display memory usage")
 memusage ;;
 *)
 clear
 echo "Sorry, wrong selection";;
 esac
done
clear

实现效果:

菜单栏

方法三:

#!/bin/bash
#脚本进入提示:
cat <<end
        1)function1
        2)function2
        3)function3
        q)exit
end
read -p "请选择:" sl
case $sl in
        1)
                fanction1
                ;;
        2)
                function2
                ;;

        3)
                function3
                ;;
        q)
                exit
                ;;
esac

实现效果:

菜单栏

 

上一篇:day68-CSS-float浮动,clear清除浮动,overflow溢出


下一篇:消除浮动方法