-
-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
interp: interprets select
incorrectly
#969
Comments
mvdan
changed the title
gosh interprets
interp: interprets Feb 3, 2023
select
incorrectlyselect
incorrectly
Thanks for reporting; the parser supports this, but the interpreter incorrectly handles it like a |
riacataquian
added a commit
to riacataquian/sh
that referenced
this issue
Feb 16, 2023
the parser already supports `select` commands but the interpreter treats it just like any other `for` command given the syntax: ``` select name [in words ...]; do commands; done ``` fix support by: * expanding and printing the words following `in`, to generate a list of items, each preceeded by a number * assigning the selected option to a special variable in Bash called `REPLY` * support `PS3`, another special variable in Bash, which can be set to the prompt while the shell awaits for input. if not provided, defaults to `#?`: ``` $ bash -c 'PS3="pick one: "; select SEL in foo; do echo $REPLY; break; done' 1) foo pick one: ``` additionally, `select` should loop until an input is provided. in case of an invalid input, the name will be empty fixes mvdan#969
riacataquian
added a commit
to riacataquian/sh
that referenced
this issue
Feb 16, 2023
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: * expanding and printing the words following `in`, to generate a list of items, each preceeded by a number and a close parenthesis * assigning the selected option to a special variable in Bash called `REPLY` * support `PS3`, another special variable in Bash, which can be set to the prompt while the shell awaits for input. if not provided, defaults to `#?`: additionally, `select` should loop until an input is provided. in case of an invalid input, the name will be empty ``` $ bash -c 'select SEL in foo; do echo $REPLY; break; done' 1) foo 1) foo 1) foo 1 ``` fixes mvdan#969
riacataquian
added a commit
to riacataquian/sh
that referenced
this issue
Feb 16, 2023
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: * expanding and printing the words following `in`, to generate a list of items, each preceeded by a number and a close parenthesis * display the prompt and read the line from stdin * assigning the selected option to a special variable in Bash called `REPLY` * support `PS3`, another special variable in Bash, which can be set to the prompt while the shell awaits for input. if not provided, defaults to `#?`: additionally, `select` should loop until an input is provided. in case of an invalid input, the name will be empty ``` $ bash -c 'select SEL in foo; do echo $REPLY; break; done' 1) foo 1) foo 1) foo 1 ``` fixes mvdan#969
riacataquian
added a commit
to riacataquian/sh
that referenced
this issue
Feb 16, 2023
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: * expanding and printing the words following `in`, to generate a list of items, each preceeded by a number and a close parenthesis * display the prompt and read the line from stdin * assigning the selected option to a special variable in Bash called `REPLY` * support `PS3`, another special variable in Bash, which can be set to the prompt while the shell awaits for input. if not provided, defaults to `#?`: additionally, `select` should loop until an input is provided. in case of an invalid input, the name will be empty ``` $ bash -c 'select SEL in foo; do echo $REPLY; break; done' 1) foo 1) foo 1) foo 1 ``` fixes mvdan#969
mvdan
pushed a commit
that referenced
this issue
Feb 25, 2023
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 the interpreter by: * expanding and printing the words following `in`, to generate a list of items, each preceeded by a number and a close parenthesis * display the prompt and read the line from stdin * assigning the selected option to a special variable in Bash called `REPLY` * support `PS3`, another special variable in Bash, which can be set to the prompt while the shell awaits for input. if not provided, defaults to `#?`: Additionally, `select` should loop until a valid input is provided. Fixes #969.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following example shows differences between
bash
andgosh
in interpretingselect
operator:gosh
selects the first option without prompt,bash
prompts for option selection and correctly assigns the selected value.The text was updated successfully, but these errors were encountered: