We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I try to increment numbers prefixed with zeros. I used expr to convert them to decimal. Because bash thinks they are octal:
expr
$ x="0008" $ echo "$((x + 1))" -bash: 0008: value too great for base (error token is "0008") $ echo "$(expr "$x" + 1)" # <- works but throws SC2003 9
The text was updated successfully, but these errors were encountered:
Okay I solved it using:
$ shopt -s extglob $ x="0008" $ x="${x##+(0)}" $ echo "$((x + 1))" 9
Maybe it is worth mentioning it at https://github.com/koalaman/shellcheck/wiki/SC2003
Sorry, something went wrong.
As an alternative to removing the leading zeroes, you can specify the base for the number:
$ x=0008 $ echo $((10#$x + 1)) 9
I have documented it on the wiki: https://github.com/koalaman/shellcheck/wiki/SC2003
No branches or pull requests
I try to increment numbers prefixed with zeros. I used
expr
to convert them to decimal. Because bash thinks they are octal:The text was updated successfully, but these errors were encountered: