sh
sh copied to clipboard
interp: wrong result when evaluating arithmetic expressions
Simple script to recreate:
$ cat test.sh
let a=5+4; echo $a # 9
let "a = 5 + 4"; echo $a # 9
let a++; echo $a # 10
let "a = 4 * 5"; echo $a # 20
let "a = 2 + 30"; echo $a # 32
Ran in bash:
$ /test.sh
9
9
10
20
32
Versus interp via gosh:
$ go run ./cmd/gosh test.sh
9
9
10
10
10
Results are wrong starting from the 4th script onwards.
This one might be trickier than you think: the problem here is likely that the quoting is preventing the parser from doing its job, as it falls back to parsing the arithmetic expression as an opaque DblQuoted word rather than the proper ArithmExpr with the assignment and addition.
In fact, is this not a dupe of https://github.com/mvdan/sh/issues/754?
I'm going to say that this is a dupe of #754 :) please say if I misunderstood.