Skip to content
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

Closed
Zebradil opened this issue Feb 2, 2023 · 1 comment · Fixed by #972
Closed

interp: interprets select incorrectly #969

Zebradil opened this issue Feb 2, 2023 · 1 comment · Fixed by #972
Assignees

Comments

@Zebradil
Copy link

Zebradil commented Feb 2, 2023

The following example shows differences between bash and gosh in interpreting select operator:

$ gosh -c 'select SEL in foo bar baz; do echo "Selected $SEL"; break; done'
Selected foo
$ bash -c 'select SEL in foo bar baz; do echo "Selected $SEL"; break; done'
1) foo
2) bar
3) baz
#? 3
Selected baz

gosh selects the first option without prompt, bash prompts for option selection and correctly assigns the selected value.

@mvdan mvdan changed the title gosh interprets select incorrectly interp: interprets select incorrectly Feb 3, 2023
@mvdan
Copy link
Owner

mvdan commented Feb 3, 2023

Thanks for reporting; the parser supports this, but the interpreter incorrectly handles it like a for.

@riacataquian riacataquian self-assigned this Feb 14, 2023
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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants