Warn about different behavior between bash and expr

Marcello Nuccio ARPAE
2021-10-14 12:08:02 +02:00
parent a1c06a3938
commit a81b7a6260

@@ -14,6 +14,18 @@ i=$((1+2))
l=${#var}
```
**WARNING:** constants with a leading 0 are interpreted as octal numbers by bash, but not by expr. Then you should specify the base when a leading zero may occur:
```sh
$ x=08
$ echo $(expr 1 + $x)
9
$ echo $((1 + $x))
-bash: 1 + 08: value too great for base (error token is "08")
$ echo $((1 + 10#$x))
9
```
See [issue #1910](https://github.com/koalaman/shellcheck/issues/1910#issuecomment-610439789)
### Rationale:
[To quote POSIX:](https://pubs.opengroup.org/onlinepubs/009695399/utilities/expr.html#tag_04_50_17)