Using {} in variable names helps eliminate ambiguity when performing variable expansion.
Consider the two variables var and varname . Suppose you wanted to add the name string to the var variable. You cannot say $varname , because it will result in the extension of the varname variable. However, by saying ${var}name , you can achieve the desired result.
$ var="This is var variable." $ varname="This is varname variable." $ echo $varname This is varname variable. $ echo ${var}name This is var variable.name
Braces are also required when accessing any element of the array.
$ a=( foo bar baz )
Quote from info bash :
Any element of an array may be referenced using ${name[subscript]}. The braces are required to avoid conflicts with pathname expansion.
source share