Parameter expansions

Length

${#foo} Length of $foo

Substrings

${foo:0:3} Substring (position, length)
${foo:(-3):3} Substring from the right

Manipulation

str=“HELLO WORLD!“
echo ”${str,}” #=> “hELLO WORLD!” (lowercase 1st letter)
echo ”${str,,}” #=> “hello world!” (all lowercase)

str=“hello world!“
echo ”${str^}” #=> “Hello world!” (uppercase 1st letter)
echo ”${str^^}” #=> “HELLO WORLD!” (all uppercase)

Default values

${foo:-val} $foo, or val if unset (or null)
${foo:=val} Set $foo to val if unset (or null)
${foo:+val} val if $foo is set (and not null)
${foo:?message} Show error message and exit if $foo is unset (or null)