Shell select用法

5040阅读 0评论2012-09-17 rocky-ghu
分类:LINUX

select 表达式是一种bash的扩展应用,动作包括:
(1)、自动用1,2,3,4列出菜单 (没有echo指令,自动显示菜单
(2)、自动read输入选择 (没有 read指令,自动输入
(3)、赋值给变量 (没有赋值指令,自动输入数字后,赋值字符串给变量

while
echo "display current netconfig:"
do
select vi in "ifconfig -a" "hosts" "netmasks" "quit"
    do
    case $vi in
         "ifconfig -a") /sbin/ifconfig -a;;
         "hosts") more hosts;;
         "netmasks") more netmasks;;
         "quit") exit 0;;
         *) continue;;
        esac
        break
    done
done

执行效果

#sh test
display current netconfig
 1) ifconfig -a
 3) netmasks
 2) hosts
 4) quit
上一篇:Vi从其他文件复制代码
下一篇:Syslinux同时引导Linux和winpe