Skip to content

Files

Latest commit

 

History

History
29 lines (18 loc) · 651 Bytes

SC2125.md

File metadata and controls

29 lines (18 loc) · 651 Bytes

Pattern: Malformed brace expansion in assignment

Issue: -

Description

echo *.png {1..9} expands to all png files and numbers from 1 to 9, but var=*.png or var={1..9} will just assign the literal strings '*.png' and '{1..9}'.

To make the variable contain all png files or 1 through 9, use an array as demonstrated.

If you intended to assign these values as literals, quote them (e.g. var="*.png").

Example of incorrect code:

foo={1..9}
echo $foo

Example of correct code:

foo=( {1..9} )
echo "${foo[@]}"

Further Reading