Skip to content
New issue

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

$(( expression )) error? #739

Closed
wisecracker-bazza opened this issue Sep 28, 2016 · 1 comment
Closed

$(( expression )) error? #739

wisecracker-bazza opened this issue Sep 28, 2016 · 1 comment

Comments

@wisecracker-bazza
Copy link

Take the code below.
[code]

!/bin/sh

txt="1234567890"
echo "$(( $txt ))"
echo "$(( ${#txt} - 1 ))"
echo "$(( #txt - 1 ))"
[/code]
Shell Check ERROR window.

[code]
$ shellcheck myscript

Line 3:
echo "$(( $txt ))"
^-- SC2004: $/${} is unnecessary on arithmetic variables.

$
[/code]
Your code says '$/${} are unnecessary with no other errors.
Now try running line 5 on sh, bash, ksh and zsh.
This is at least one exception to the rule.
TIA.
Bazza.

@koalaman
Copy link
Owner

koalaman commented Oct 1, 2016

You're right, but shellcheck also does not produce a warning for echo "$(( ${#txt} - 1 ))".

It only produces a warning where the $ is unnecessary, on line 3.

I've updated the wiki to mention this explicitly.

@koalaman koalaman closed this as completed Oct 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants