-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2054
koalaman edited this page Sep 29, 2016
·
2 revisions
flags=("-l", "-d", "--sort=size")
ls "${flags[@]}"
flags=("-l" "-d" "--sort=size")
ls "${flags[@]}"
You appear to have used commas to separate array elements in an array assignment. Other languages require this, but bash instead treats the commas as literal strings.
In the problematic code, the first element is -l,
with the trailing comma, and the executed command ends up being ls -l, -d, --sort=size
.
In the correct code, there are no trailing commas and the command will be ls -l -d --sort=size
as expected.
None (if you actually want a trailing comma in your strings, move it inside the quotes).