-3

For the lexical analysis in a POSIX shell, from http://pubs.opengroup.org/onlinepubs/007904875/utilities/xcu_chap02.html

7. [Assignment preceding command name]

a. [When the first word]

If the TOKEN does not contain the character ’=’, rule 1 is applied. Otherwise, 7b shall be applied.

b. [Not the first word]

If the TOKEN contains the character:

— If it begins with ’=’, the token WORD shall be returned.

— If all the characters preceding ’=’ form a valid name (see XBD Section 3.231), the token ASSIGNMENT_WORD shall be returned. (Quoted characters cannot participate in forming a valid name.)

— Otherwise, it is unspecified whether it is ASSIGNMENT_WORD or WORD that is returned. Assignment to the NAME shall occur as specified in Section 2.9.1.

  1. What does 'the first word' mean?

    What case is 'When the first word'?

    What case is 'Not the first word'?

  2. 'When the first word', What case is 'If the TOKEN does not contain the character ’=’'?
  3. When 'Not the first word',

    • What case is 'If it begins with ’=’'?

    • What case is 'Otherwise'?

  • 2
    I'm puzzled by the silent downvotes. Formal grammar rules are certainly hard to understand and POSIX is definitely on topic here. – jlliagre Dec 28 '16 at 3:33
2
  1. What does 'the first word' mean?

The first token that is not an operand.

What case is 'When the first word'?

When the first token that is not an operand is analyzed.

What case is 'Not the first word'?

This case is used to allow the processing of multiple assignments present in the same line.

  1. 'When the first word', What case is 'If the TOKEN does not contain the character ’=’'?

When the first token that is not an operand doesn't contain an = sign, this is not an assignment and so it will be processed as a command name (rule 1).

  1. When 'Not the first word',

    • What case is 'If it begins with ’=’'?

That would be something like:

=123
  • What case is 'Otherwise'?

There are two 'otherwise', the first one would be something like:

invalid%variable+name=123

the second 'otherwise' covers the cases where a word that is not the first one doesn't contain an assignment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.