Linux&shell之高级Shell脚本编程-创建菜单
2013-08-15 13:03
656 查看
写在前面:案例、常用、归类、解释说明。(By Jim)
创建菜单
#!/bin/bash
# testing the script
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 menu\n\n"
echo -en "\t\tEnter option:"
(这段代码很有意思,会显示目录的效果)
创建菜单函数
function diskspace {
clear
df -k
}
function whoseon {
clear
who
}
function memusage {
clear
cat /proc/meminfo
}
添加菜单逻辑
case $option in
0)
break ;;
1)
diskspace ;;
2)
whoseon ;;
3)
menusage ;;
*)
clear
echo "Sorry,wrong selection" ;;
esac
完整的菜单如下:
#!/bin/bash
# testing the script
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 menu\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)
menusage ;;
*)
clear
echo "Sorry,wrong selection" ;;
esac
echo -en "\n\n\t\tHit any key to continue"
read -n 1 line
done
clear
创建菜单
#!/bin/bash
# testing the script
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 menu\n\n"
echo -en "\t\tEnter option:"
(这段代码很有意思,会显示目录的效果)
创建菜单函数
function diskspace {
clear
df -k
}
function whoseon {
clear
who
}
function memusage {
clear
cat /proc/meminfo
}
添加菜单逻辑
case $option in
0)
break ;;
1)
diskspace ;;
2)
whoseon ;;
3)
menusage ;;
*)
clear
echo "Sorry,wrong selection" ;;
esac
完整的菜单如下:
#!/bin/bash
# testing the script
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 menu\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)
menusage ;;
*)
clear
echo "Sorry,wrong selection" ;;
esac
echo -en "\n\n\t\tHit any key to continue"
read -n 1 line
done
clear
相关文章推荐
- Linux&shell之高级Shell脚本编程-创建函数
- Linux&shell之高级Shell脚本编程-创建函数
- Linux学习-高级shell脚本编程(二)初识sed和gawk
- Shell脚本编程之创建文本菜单
- shell脚本编程:Linux的自动化逻辑卷创建脚本
- Linux Shell 脚本编程之函数
- [linux] shell脚本编程-ubuntu创建vsftpd服务
- Linux命令与shell脚本编程学习笔记-16创建函数
- *Linux Shell 高级编程技巧3----运行级别脚本介绍
- *Linux Shell 高级编程技巧4----几个常用的shell脚本例子
- Linux学习-高级shell脚本编程(一)函数的妙用
- Linux下创建shell脚本文件
- Linux执行shell脚本方式及区别&命令后台运行
- linux bash Shell脚本经典之Fork炸弹解析:() { :|:& };:
- Linux之Shell脚本创建
- Linux-Shell脚本编程-学习-7-总结前面开启后面的学习
- Linux编程Shell脚本执行方法
- Shell脚本高级编程 一 初识sed和gawk
- Linux命令行与Shell脚本编程[序]
- Linux脚本(shell)编程(一) 简单入门HelloWorld