mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Warn about different behavior between bash and expr
12
SC2003.md
12
SC2003.md
@@ -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)
|
||||
|
Reference in New Issue
Block a user