diff --git a/SC2003.md b/SC2003.md index 04788a1..3d0f80d 100644 --- a/SC2003.md +++ b/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)