This is a small cheat sheet to remind me of how parameter expansion works in unix shells.
shell parameter expansion
${a-b}# return $a if set, otherwise b${a:-b}# return $a if set and not null, otherwise b${a=b}# return $a if set, otherwise set $a to b${a:=b}# return $a if set and not null, otherwise set $a to b${a?b}# return $a if set, otherwise crash${a:?b}# return $a if set or null, otherwise crash${a+b}# return b if $a set, otherwise null${a:+b}# return b if $a set or null, otherwise null${#a}# return length of $a${a:b:c}# returnccharacters starting from offsetbin$a${a%b}# remove smallest patternbat the end of$a${a%%b}# remove largest patternbat the end of$a${a#b}# remove smallest patternbat the start of$a${a##b}# remove largest patternbat the start of$a
non-standard (ok in busybox ash and bash, not ok in dash)
${a/b/c}# replacebwithcin$a