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

Use [*] instead of [@] for array expansion inside a string #2098

Merged
merged 1 commit into from Mar 25, 2019

Conversation

pcahyna
Copy link
Member

@pcahyna pcahyna commented Mar 22, 2019

Relax-and-Recover (ReaR) Pull Request Template

Please fill in the following items before submitting a new pull request:

Pull Request Details:
  • Type: Style Cleanup

  • Impact: Low

  • Reference to related issue (URL):
    https://github.com/rear/rear/pull/1887/files#r268264260

  • How was this pull request tested?
    Code analysis and experimenting with analogous snippets of bash code.

  • Brief description of the changes in this pull request:
    Array expansion inside strings like "aaa ${boot_list[@]} bbb" splits the string into several strings:

boot_list=( foo bar )
"aaa ${boot_list[@]} bbb"

-> "aaa foo" "bar bbb" instead of "aaa foo bar bbb". This is probably unintended, although harmless in this case.
Change [@] to a more intuitive [*], which keeps the result of expansion as one string.
See https://github.com/koalaman/shellcheck/wiki/SC2145

"aaa ${boot_list[@]} bbb" splits the string into several strings:
boot_list=( foo bar )
"aaa ${boot_list[@]} bbb" -> "aaa foo" "bar bbb" instead of
"aaa foo bar bbb". This is probably unintended, although harmless in
this case.
Change [@] to a more intuitive [*], which keeps the result of
expansion as one string.
@jsmeix
Copy link
Member

jsmeix commented Mar 25, 2019

@rmetrich
I assign this to you because you did #2096
and #2097 before
(and I know nothing about what syntax the bootlist command needs).

Copy link
Member

@jsmeix jsmeix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rmetrich
Copy link
Contributor

There is indeed a diff, but not really seen when echoing:

$ boot_list=( foo bar )

$ for v in "aaa ${boot_list[@]} bbb"; do echo "$v"; done
aaa foo
bar bbb

$ for v in "aaa ${boot_list[*]} bbb"; do echo "$v"; done
aaa foo bar bbb

@jsmeix jsmeix self-assigned this Mar 25, 2019
@rmetrich rmetrich merged commit e14baee into rear:master Mar 25, 2019
@jsmeix jsmeix added fixed / solved / done minor bug An alternative or workaround exists labels Mar 25, 2019
@jsmeix jsmeix added this to the ReaR v2.5 milestone Mar 25, 2019
@jsmeix
Copy link
Member

jsmeix commented Mar 25, 2019

@pcahyna
thank you for your precise inspection of the details is the code!

Because of this I added
#1068 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup fixed / solved / done minor bug An alternative or workaround exists
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants