Open scop opened 1 year ago
Similarly, in Bash, case $word in
and here strings <<< $word
are unnecessary in most cases. Some notes:
==
, !=
, and =~
in conditional commands [[ ]]
should not be removed. The quote has special meaning in those contexts.[[ ... ]]
contains $*
or ${arr[*]}
, they need to be quoted as "$*"
or "${arr[*]}"
. Bash <= 4.2 has a bug that the joining character (the first character of IFS) is replaced by a whitespace
.case
and in here documents contain $*
or ${arr[*]}
, they need to be quoted. Bash <= 4.4 has a bug. [[:space:]|&;<>\`"$]
, the quote for these characters cannot be removed. For example, var="a b c"
cannot be unquoted to be var=a b c
.Edit: Bash <= 4.3 has a bug in here strings: https://github.com/koalaman/shellcheck/issues/1009#issuecomment-488395630, so here strings need to be quoted as far as bash <= 4.3 is supported.
Thanks for the info. What I'm specifically thinking of are the simple "$foo"
cases. Any known issues dropping the quotes from them in the mentioned contexts?
For the simple case "$foo"
, I think there aren't any problems in the mentioned contexts at least in Bash. They can be always unquoted in
var=$foo
),==
, !=
, and =~
) ([[ $foo == "$bar" ]]
),case $foo
)<<< $foo
)
It seems there's room for some more removal of unnecessary quotes on simplify; to my knowledge word splitting does not occur:
[[ ]]
-- some quotes are removed in this context already, but not e.g from the right side of things like[[ $foo == "$bar" ]]
=
and+=
)I don't know offhand how this is for other shells besides bash, but thought I'd drop the suggestion here for comments already based just on the bash info.