mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2080 (markdown)
30
SC2080.md
Normal file
30
SC2080.md
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
## Numbers with leading 0 are considered octal.
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
echo $(( 16 - 08 ))
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
echo $(( 16 - 8 ))
|
||||||
|
```
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
ShellCheck found an integer literal with a leading zero, but containing the digits 8 or 9.
|
||||||
|
|
||||||
|
This is invalid, as the integer will be interpreted as an octal value (e.g. 0777 == 0x1FF == 511).
|
||||||
|
|
||||||
|
To have the value parsed in base 10, either remove the leading zeros as in the example, or specify the radix explicitly:
|
||||||
|
|
||||||
|
echo $((10#08))
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
### Related resources:
|
||||||
|
|
||||||
|
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user