Pattern: Use of ,
to separate Bash array elements
Issue: -
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.
Example of incorrect code:
flags=("-l", "-d", "--sort=size")
ls "${flags[@]}"
The first element is -l,
with the trailing comma, and the executed command ends up being ls -l, -d, --sort=size
.
Example of correct code:
flags=("-l" "-d" "--sort=size")
ls "${flags[@]}"
The trailing commas have been removed, and the command will be ls -l -d --sort=size
as expected.