zoukankan      html  css  js  c++  java
  • select

    select


     语法:

    select name [in words …]; do commands; done

    作用:

    生成由words序列组成的一个简单菜单选项。一般多用于交互式shell。每个菜单项对应前面一个数字编号,你输入菜单前的编号,就选中了该菜单项。select会重复提示选择,除非 commands 中出现终止语句,如break、return、exit等。

    name变量的值就是你选中的菜单编号,如果你选择的菜单编号不存在,则name值为空,即''。

    你作为选择的输入,无论是否是菜单里的,都一律保存在变量REPLY中。以下列子可以更好的说明这些:

     1 [root@host usr]# select fname in *; do echo you picked $fname ($REPLY);  done
     2  1) bin
     3  2) etc
     4  3) games
     5  4) include
     6  5) lib
     7  6) lib64
     8  7) libexec
     9  8) local
    10  9) sbin
    11 10) share
    12 11) src
    13 12) tmp
    14 #? 5
    15 you picked lib (5)
    16 #? noafudofn               # 胡乱输入
    17 you picked (noafudofn)     # fname等于''

    果省略name后的[in words …],则等同于name in "$@"。菜单项默认为参数列表。

    本篇文章出自“国民时代”,转载请注明转载出处。
  • 相关阅读:
    concurrent-锁
    字符串查找字符串
    指针作为函数返回值
    数组名作为函数参数
    指针和函数
    多级指针
    指针数组
    指针运算
    指针和数组
    const修饰的指针类型
  • 原文地址:https://www.cnblogs.com/ChinaGo/p/9600942.html
Copyright © 2011-2022 走看看