From 8a6c084a982657c44e3640f455f3b4e6d113855f Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Fri, 7 Sep 2018 09:50:50 -0700 Subject: [PATCH] Created SC2080 (markdown) --- SC2080.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 SC2080.md diff --git a/SC2080.md b/SC2080.md new file mode 100644 index 0000000..7e5a16b --- /dev/null +++ b/SC2080.md @@ -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! \ No newline at end of file