Variable values can be accessed and manipulated using variable expansion. Basic expansion is done by preceding the variable name with the $ character. Other types of expansion can be used to return portions or the length of variables, use default or alternate values, assign default or alternate values, and more.
Variable Expansion Format
${variable}
value of variable
${#variable}
length of variable
${variable:–word}
value of variable if set and not null, else print word. If: is omitted, variable is only checked if it is set.
${variable:=word}
value of variable if set and not null, else variable is set to word, then expanded. If: is omitted, variable is only checked if it is set.
${variable:?}
value of variable if set and not null, else print "variable: parameter null or not set". If: is omitted, variable is only checked if it is set.
${variable:?word}
value of variable if set and not null, else print value of word and exit. If: is omitted, variable is only checked if it is set.
${variable:+word}
value of word if variable is set and not null, else nothing is substituted. If: is omitted, variable is only checked if it is set.
${variable#pattern}
value of variable without the smallest beginning portion that matches pattern
${variable##pattern}
value of variable without the largest beginning portion that matches pattern
${variable%pattern}
value of variable without the smallest ending portion that matches pattern
${variable%%pattern}
value of variable without the largest ending portion that matches pattern