help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What does `echo xxx 1>&2xxx` do?


From: Chet Ramey
Subject: Re: What does `echo xxx 1>&2xxx` do?
Date: Sat, 8 May 2021 21:30:09 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.9.1

On 5/8/21 8:01 PM, Peng Yu wrote:


You can get a long way by simply reading the POSIX grammar and rules for
recognizing and classifying tokens. These are the two relevant rules from

I don't see the definition of metacharacters in the POSIX document. So
this is definition is from the nomenclature used in bash?

You might consider looking at the bash manual for the definition.


So the manual defines how to determine what are words and operators.
It says how to determine operators. But the definition seems to be
recursive making it hard to directly tell what are operators.

The definition of `control operator' is right there in the manual. If you
want to follow POSIX, and there's no reason not to, an operator is a
control operator or a redirection operator. The redirection operators are
listed in the REDIRECTION section.


Are there only a limited number of operators? If so, is there a way to
print all the operators supported by bash?

No.


Are `${`, `$(` and `$((` operators?

No.

So this means that a character is always preferred to be associated
with the following characters, rather than with the preceding
characters, to form a token.

Obviously not. Consider a string of digits forming a number, for example,
delimited by a space. The last digit is associated with the previous
digits to form a token.

Could you show some examples for this
case?

What case?

Does this mean that one will always look ahead to determine what is a
token?

Sometimes. It depends on the delmiter and what the grammar is expecting.

What is the number of characters to look ahead?

It varies, but usually one. In some circumstances, two.

Could you give examples for the NAME and ASSIGNMENT_WORD cases?

Come on. A NAME is as defined in the man page and POSIX. An ASSIGNMENT_WORD
is an assignment statement. It's in

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_10_02


So because this context-dependency, it is not possible to determine
the token just by lexical analysis? What specific syntactic
information is fed back to the lexer in order to determine whether it
is a WORD, a NAME, or an ASSIGNMENT_WORD?

Look at the link above. A token is a NAME or ASSIGNMENT_WORD in specific
circumstances, and a reserved word or WORD otherwise.

The lexical analyzer knows the parser state encoded in the parser_state
variable and the previous two tokens.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]