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: let arithmetic expression is not properly evaluated when expression is enclosed in string #754

Open
riacataquian opened this issue Nov 5, 2021 · 1 comment

Comments

@riacataquian
Copy link
Collaborator

Given let.sh as the input file:

#!/bin/bash

let "varone=1" "vartwo=++varone"; echo $varone, $vartwo
let "myvar=16 << 2"; echo $myvar

let varone=1 vartwo=++varone; echo $varone, $vartwo
let myvar="16 << 2"; echo $myvar

On bash:

$ ./let.sh
2, 2
64
2, 2
64

Versus on gosh:

$ gosh let.sh
,

2, 2
0

Gosh correctly evaluated let varone=1 vartwo=++varone but not let myvar="16 << 2".

@mvdan
Copy link
Owner

mvdan commented Nov 8, 2021

This is similar to #743, but applied to arithmetic expressions rather than assignment expressions.

I think it makes sense to do this kind of "second pass parsing", where we do an arithmetic expression parse on the expanded string field while interpreting. We can't pretend to only support parsing statically, because then we lose too much compatibility with sh/bash, as you point out.

I think my only worry would be the performance; we don't want to be re-parsing absolutely every string that goes through the arithmetic expression interpreter. One way would be to only do this re-parsing if a field was a quoted string.

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

No branches or pull requests

2 participants