当前位置: > shell编程 >

shell中使用内置命令select生成程序菜单的例子

时间:2014-09-15 02:27来源:linux.it.net.cn 作者:it

shell中使用内置命令select生成程序菜单的例子,以下的脚本可以提供给用户一系列的选项去选择。
其中定义的finished选项挺好。
 

复制代码代码如下:
#!/bin/bash
directorylist="Finished $(ls /)"
PS3='Directory to process? ' # Set a useful select prompt
until [ "$directory" == "Finished" ]; do
    printf "%b" "annSelect a directory to process:n" >&2
    select directory in $directorylist; do
        # User types a number which is stored in $REPLY, but select
        # returns the value of the entry
        if [ "$directory" = "Finished" ]; then
            echo "Finished processing directories."
            break
        elif [ -d "/$directory" ]; then
            echo "You chose number $REPLY, processing $directory ..."
            # Do something here
            break
        else
            echo "Invalid selection!"
        fi # end of handle user's selection
    done # end of select a directory
done # end of while not
 
 
(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容