mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.2k stars 340 forks source link

interp: handle select clause #972

Closed riacataquian closed 1 year ago

riacataquian commented 1 year ago

the parser already supports the select command but the interpreter treats it just like any other for command

given the syntax:

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

fix support by:

additionally, select should loop until an input is provided. in case of an invalid input, the name will be empty

$ bash -c 'PS3="pick one: "; select SEL in foo; do echo $REPLY; break; done'
1) foo
pick one:
1) foo
pick one:
1) foo
pick one: 1

fixes https://github.com/mvdan/sh/issues/969