String Operations
${varname#pattern} Remove up to the FIRST occurrence of the match from the beginning of the line
${varname##pattern} Remove up to the LAST occurrence of the match from the beginning of the line
${varname%pattern} Remove the FIRST occurrence of the match starting from the end of the line
${varname%%pattern} Remove the LAST occurrence of the match starting from the end of the line
${varname/pattern/string} Replace matching pattern with string
${varname/#pattern/string} Replace matching pattern at the BEGINNING of the line with string
${varname/%pattern/string} Replace matching pattern at the END of the line with string
${varname//pattern/string} Replace ALL matching occurrences of pattern with string
${varname:offset:length} Returns the substring of $varname starting at offset and up to the length of characters
${varname: length} Returns the substring of $varname starting at offset from the END
Variable Manipulations
${#varname} Get length of variable
${!pattern*} Indirect reference. Matches all variables names that match the pattern
${varname^} Transform first character of string to uppercase
${varname^^} Transform all characters of string to uppercase
${varname,} Transform first character of string to lowercase
${varname,,} Transform all characters of string to lowercase
Expansions to handle empty variables
${varname:$var} If $varname isn't null return it's value, else return $var
${varname:=$var} If $varname isn't null return it's value, else assign it to $var and return it's value
${varname:?$var} If $varname isn't null return it's value, otherwise print varname: $var and abort
${varname:+$var} If $varname isn't null, return $var, otherwise return null
String Operations Examples
VAR="The quick brown fox jumped over the fox"
${VAR#*fox} jumped over the fox
${VAR%fox*} The quick brown fox jumped over the
${VAR%%fox*} The quick brown
${VAR/fox/dog} The quick brown dog jumped over the fox
${VAR//fox/dog} The quick brown dog jumped over the dog
${VAR/#The/A} A quick brown fox jumped over the fox
${VAR/%fox/dog} The quick brown fox jumped over the dog