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

Bad arithmetic expansion not recognised #115

Open
Niols opened this issue Oct 31, 2019 · 0 comments
Open

Bad arithmetic expansion not recognised #115

Niols opened this issue Oct 31, 2019 · 0 comments

Comments

@Niols
Copy link
Member

Niols commented Oct 31, 2019

The following

$((a) || (b))

is parsed as

[
  "Word",
  "$((a) || (b))",
  [ [ "WordLiteral", "$((a) || (b))" ] ]
]

The standard says:

The syntax of the shell command language has an ambiguity for expansions beginning with "$((", which can introduce an arithmetic expansion or a command substitution that starts with a subshell. Arithmetic expansion has precedence; that is, the shell shall first determine whether it can parse the expansion as an arithmetic expansion and shall only parse the expansion as a command substitution if it determines that it cannot parse the expansion as an arithmetic expansion. The shell need not evaluate nested expansions when performing this determination. If it encounters the end of input without already having determined that it cannot parse the expansion as an arithmetic expansion, the shell shall treat the expansion as an incomplete arithmetic expansion and report a syntax error. A conforming application shall ensure that it separates the "$(" and '(' into two tokens (that is, separate them with white space) in a command substitution that starts with a subshell. For example, a command substitution containing a single subshell could be written as:

$( (command) )
@Niols Niols added this to the Software Heritage milestone Oct 31, 2019
Niols added a commit that referenced this issue Nov 25, 2019
yurug pushed a commit that referenced this issue Feb 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant