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

SC2128 is not triggered with read -ra stringarray <<<"${linevariable}"; Expanding an array without an index only gives the first element #1636

Closed
evandrocoan opened this issue Jul 4, 2019 · 1 comment

Comments

@evandrocoan
Copy link

This code should trigger SC2128: Expanding an array without an index only gives the first element

#!/bin/bash
linevariable="var1     var2";
read -ra stringarray <<<"${linevariable}";
printf "first %s\\n" "${stringarray[0]}"
printf "second %s\\n" "${stringarray[1]}"

stringarray="${stringarray}"
printf "stringarray %s\\n" "${stringarray[0]}"

But only this triggers it:

#!/bin/bash
linevariable="var1     var2";
stringarray=(${linevariable});
printf "first %s\\n" "${stringarray[0]}"
printf "second %s\\n" "${stringarray[1]}"

stringarray="${stringarray}"
printf "stringarray %s\\n" "${stringarray[0]}"

Related to:

  1. SC2178 indefinitely triggers SC2128 when it should not, i.e., after overriding an array variable with a single string #1630 SC2178 indefinitely triggers SC2128 when it should not, i.e., after overriding an array variable with a single string
@koalaman
Copy link
Owner

koalaman commented Jul 4, 2019

So it should! This failed because ShellCheck only looked for -a without accounting for things like -ra. This has now been fixed, thanks!

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