BASH-Variable Expansion Formats

Variable Expansion Formats

${#variable} length of variable
${variable:–word} value of variable if set and not null, else print word
${variable:word} value of variable if set and not null, else  variable is set to word, then expanded
${variable:+word} value of word if variable is set and not null, else nothing is substituted
${variable:?} value of variable if set and not null, else print ‘variable: parameter null or not set
${variable:?word} value of variable if set and not null, else print value of word and exit
${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
${variable//pattern1/pattern2} replace all occurrences of pattern1 with pattern2 in variable