Parameter expansion

Prefix and Suffix Deletion

Remove shortest match of pattern from start of string.

${VAR#PATTERN}

Remove longest match of pattern from start of string.

${VAR##PATTERN}

Remove shortest match of pattern from end of string.

${VAR%PATTERN}

Remove longest match of pattern from end of string.

${VAR%%PATTERN}

Length

Lenght of var in characters.

${#VAR}

Default Value

If VAR is empty or unset, use STRING as its value.

${VAR:-STRING}

If VAR is unset, use STRING as its value.

${VAR-STRING}

If VAR is empty or unset, set the value of VAR to STRING.

${VAR:=STRING}

If VAR is unset, set the value of VAR to STRING.

${VAR=STRING}

If VAR is not empty, use STRING as its value.

${VAR:+STRING}

If VAR is set, use STRING as its value.

${VAR+STRING}

Display an error if empty or unset.

${VAR:?STRING}

Display an error if unset.

${VAR?STRING}