Linux shell select实现菜单选择

Linux shell select实现菜单选择

select语句使用方法(产生菜单选择)

语法:

select 变量name in seq变量

do

action

done

实例:

#!/bin/sh

select ch in "begin" "end" "exit"
do
    case $ch in
    "begin")
        echo "start something"
        ;;
    "end")
        echo "stop something"
        ;;
    "exit")
        echo "exit"
        break;
        ;;
    *)
        echo "ignorant"
        ;;
    esac
done;

运行效果:

yuxuecheng@linux:~/shellSource> ./select_test.sh 
1) begin
2) end
3) exit
#? 1
start something
#? 2
stop something
#? 4
ignorant
#? begin
ignorant
#? 3
exit

说明:select是循环选择,一般与case语句使用。

猜你喜欢

转载自jayceyxc.iteye.com/blog/2246885
今日推荐