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
Bash arithmetic expansion diagnostics #255
Comments
|
That might be tricky, because the parsing rules for array assignments are complex. In It's also a special case of some closely related bugs (IMO). Bash incorrectly considers Anyway, just sayin there's a lot to consider. I don't think just checking for |
|
I walked straight into one of these. It looks like something might have changed in bash on top of everything else because it was not new code that exploded in my face, but I have indeed a new bash version on this machine since last time I tried it. brother ~$ cat /tmp/test.sh
#!/bin/bash
slots=14
unset slotaddr
for ((i=0x82 ; i<((0x82+(slots*2))) ; i=i+2 )); do
slotaddr+=($i)
done
echo "${slotaddr[@]}"
brother ~$ shellcheck /tmp/test.sh
brother ~$ /tmp/test.sh
/tmp/test.sh: command substitution: line 9: syntax error near unexpected token `slots*2'
/tmp/test.sh: command substitution: line 9: `(0x82+(slots*2))) ; i=i+2 '
/tmp/test.sh: line 6: syntax error: arithmetic expression required
/tmp/test.sh: line 6: syntax error: `((i=0x82 ; i<((0x82+(slots*2))) ; i=i+2 ))'on bash 4.3.30(1)-release after adding the missing $ (took me a good while to understand how this suddenly could just break =)) I get the expected output ofc. brother ~$ cat /tmp/test.sh
#!/bin/bash
slots=14
unset slotaddr
for ((i=0x82 ; i<$((0x82+(slots*2))) ; i=i+2 )); do
slotaddr+=($i)
done
echo "${slotaddr[@]}"
brother ~$ shellcheck /tmp/test.sh
brother ~$ LC_ALL=C /tmp/test.sh
130 132 134 136 138 140 142 144 146 148 150 152 154 156 |
|
oh. adding a space between < and (( makes bash happy. I do not know enough about the environment to point fingers here. |
|
On Wed, Apr 1, 2015 at 7:07 AM, brother notifications@github.com wrote:
That's a bug. There were some changes to the way C-for was parsed during |
|
Forwarded your issue to bug-bash since that should probably be fixed. http://article.gmane.org/gmane.comp.shells.bash.bugs/23373 EDIT: ...and it's fixed. I guess this one didn't get a backport to 4.3. |
|
@ormaaj gee. thanks! |
|
Great edge case. Warnings have been much improved in 3cf8b9c In addition to this warning, it's now being parsed as a multidimensional array, so it may be followed by a pile of array warnings. |
The problem here is a missing
$before the((. ShellCheck’s diagnostics appear to be misleading in this case.The text was updated successfully, but these errors were encountered: