sh icon indicating copy to clipboard operation
sh copied to clipboard

interp: wrong result when evaluating arithmetic expressions

Open riacataquian opened this issue 4 years ago • 1 comments

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.

riacataquian avatar Oct 24 '21 12:10 riacataquian

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?

mvdan avatar Jul 05 '22 10:07 mvdan

I'm going to say that this is a dupe of #754 :) please say if I misunderstood.

mvdan avatar Apr 16 '23 08:04 mvdan