Skip to content

Files

Latest commit

 

History

History
29 lines (18 loc) · 749 Bytes

SC2054.md

File metadata and controls

29 lines (18 loc) · 749 Bytes

Pattern: Use of , to separate Bash array elements

Issue: -

Description

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.

Further Reading