On 21/02/2021 18:17, Joerg Schilling via austin-group-l at The Open Group wrote:
"Harald van Dijk via austin-group-l at The Open Group" 
<austin-group-l@opengroup.org> wrote:

On 21/02/2021 17:18, Joerg Schilling via austin-group-l at The Open
Group wrote:
"Harald van Dijk via austin-group-l at The Open Group" 
<austin-group-l@opengroup.org> wrote:

That is neither what the standard says nor what shells do, though.

     case x in ( (x) echo match ;; esac

is rejected because that first '(' does change the parse state, making
the second '(' invalid.

That state change does not happen in ksh and the Bourne Shell as mentioned
before.

That state change clearly does happen and the exact example that I
included and you quoted shows that it does.

$ bosh -c 'case x in ( (x) echo match ;; esac'
bosh: syntax error at line 1: `(' unexpected

It may be that you are missinterpreting the results.

I'm not. You say there's no state change that happens as a result of the first opening parenthesis. However, before the first opening parenthesis, an opening parenthesis is accepted, while after the first opening parenthesis, an opening parenthesis is not accepted. Since the two states differ in what they accept, they cannot be the same state. Therefore, the opening parenthesis did cause a state change.

The problem here is that the lexer sees the '(' as a separate token and thus it is seen as pattern. The next token is the "x" and since "x" is neither ')', nor '|', this syntax is not accepted.

The error message in both bosh and ksh is "`(' unexpected". This error message means the shell rejected the '(' token, not whatever follows. Of course it did: a pattern cannot be any arbitrary token, it has to be what the standard calls a "word", which '(' is not.

Reply via email to