shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

Add an optional(?) check for `avoid-variable-braces`

Open Kreyren opened this issue 2 years ago • 2 comments

Lot of people seems to write the code with ${var} where the common justification seems to be that adding the braces is a replacement for double-quoting to prevent globbing and word splitting (SC2086).

Additionally it seems to make the code harder to read and is messy as the alternative $var does the same thing -> Proposing to add check that will discourage the use of braces unless they are used in a variable expansion.

Kreyren avatar Sep 30 '23 21:09 Kreyren

Imagine:

a=idc
b=${a}else

You have to use curly braces in such a statement... Otherwise shell would try to find variable by name 'aelse'

I prefer not to use them for simple variable expansion because it's 2 additional characters

aeiplatform avatar Oct 05 '23 07:10 aeiplatform

Imagine:

a=idc
b=${a}else

You have to use curly braces in such a statement... Otherwise shell would try to find variable by name 'aelse'

I prefer not to use them for simple variable expansion because it's 2 additional characters -- @aeiplatform (https://github.com/koalaman/shellcheck/issues/2836#issuecomment-1748231679)

Agree that the b=${a}else and parameter expansion are a valid usage that should be excluded from the check.

This is mainly for the source code alike https://github.com/armbian/build/blob/b6fea441d1850ffd512bcd1d5f65091fdf6e5157/lib/single.sh where people put the braces on every single variable that looks ugly and bloated to me as it's adding useless characters.

Kreyren avatar Oct 05 '23 10:10 Kreyren