sh icon indicating copy to clipboard operation
sh copied to clipboard

syntax: multiline arrays are not intended correctly with "$()" in array member

Open michix opened this issue 3 years ago • 2 comments

Given the following code:

RUN_CMD=("$(foo)" \
  "bar")

When I format it with shfmt I get:

RUN_CMD=("$(foo)"
"bar")

The backslash is removed at the end (which is OK), but the second line is not intended. This only occurs when there is the $( as the first value in the array, with ( the issue does not occur.

michix avatar Feb 15 '22 08:02 michix

Minimal repro:

$ cat f.sh
arr1=($(foo)
	bar)
arr2=(foo
	bar)
$ shfmt f.sh
arr1=($(foo)
bar)
arr2=(foo
	bar)

mvdan avatar Feb 19 '22 17:02 mvdan