#2098 PR merged
: Use [*] instead of [@] for array expansion inside a string¶
Labels: cleanup
, fixed / solved / done
, minor bug
pcahyna opened issue at 2019-03-22 18:34:¶
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
jsmeix commented at 2019-03-25 09:06:¶
@rmetrich
I assign this to you because you did
https://github.com/rear/rear/pull/2096
and
https://github.com/rear/rear/pull/2097
before
(and I know nothing about what syntax the bootlist
command needs).
rmetrich commented at 2019-03-25 09:12:¶
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 commented at 2019-03-25 09:46:¶
@pcahyna
thank you for your precise inspection of the details is the code!
Because of this I added
https://github.com/rear/rear/issues/1068#issuecomment-476122565
[Export of Github issue for rear/rear.]