Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于值的Bash脚本选择选项_Bash_Ssh_Terminal - Fatal编程技术网

基于值的Bash脚本选择选项

基于值的Bash脚本选择选项,bash,ssh,terminal,Bash,Ssh,Terminal,我有一个命令要在终端中运行 例如 samplecommand-s 这在后面提供了一个选项: 选择1 选择2 关于输入问题 请输入索引: 所以我需要在终端中输入2 然而,选项1和选项2的顺序发生了变化,使得难以对特定索引进行硬编码 e、 g.可以是: 选择2 选择1 是否有办法使用提供的选项上下文,并使脚本仅选择“选项2”。您可以使用se;ect: > select: select NAME [in WORDS ... ;] do COMMANDS; done > The WO

我有一个命令要在终端中运行

例如

samplecommand-s

这在后面提供了一个选项:

  • 选择1
  • 选择2
  • 关于输入问题 请输入索引:

    所以我需要在终端中输入2

    然而,选项1和选项2的顺序发生了变化,使得难以对特定索引进行硬编码

    e、 g.可以是:

  • 选择2
  • 选择1

  • 是否有办法使用提供的选项上下文,并使脚本仅选择“选项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.
    
    请看一看。我能胜任这项工作。