【发布时间】:2019-05-17 15:09:19
【问题描述】:
我想在终端中运行一个命令。
例如。
示例命令 -s
稍后提供一个选项:
- 选项 1
- 选项 2
输入问题 请输入索引:
所以我需要在终端中输入 2。
但是,选项 1 和选项 2 的顺序发生了变化,因此很难对特定索引进行硬编码。
例如可能是:
- 选项 2
- 选项 1
有没有办法使用提供的选项的上下文并使脚本只选择“选项 2”。
【问题讨论】:
我想在终端中运行一个命令。
例如。
示例命令 -s
稍后提供一个选项:
输入问题 请输入索引:
所以我需要在终端中输入 2。
但是,选项 1 和选项 2 的顺序发生了变化,因此很难对特定索引进行硬编码。
例如可能是:
有没有办法使用提供的选项的上下文并使脚本只选择“选项 2”。
【问题讨论】:
你可以使用se;ect:
> select: select NAME [in WORDS ... ;] do COMMANDS; done
> The WORDS are expanded, generating a list of words. The
> set of expanded words is printed on the standard error, each
> preceded by a number. If `in WORDS' is not present, `in "$@"'
> is assumed. The PS3 prompt is then displayed and a line read
> from the standard input. If the line consists of the number
> corresponding to one of the displayed words, then NAME is set
> to that word. If the line is empty, WORDS and the prompt are
> redisplayed. If EOF is read, the command completes. Any other
> value read causes NAME to be set to null. The line read is saved
> in the variable REPLY. COMMANDS are executed after each selection
> until a break command is executed.
【讨论】: