Error:

Get string length

var=test
# len is 4
len=${#var}

Get substring

var=abcdefgh
# str1 is "efgh"
str1=${var:4}
# str2 is "cde"
str2=${var:2:4}

Get last N characters of the string

var=abcdefgh
# newvar is "fgh"
newvar=${var:(-3)}

Delete shortest match of substring (from front)

var=loto82
# newvar is "to82"
newvar=${var#[a-z]*o}

Delete longest match of substring (from front)

var=loto82
# newvar is "82"
newvar=${var#[a-z]*o}

Delete shortest match of substring (from back)

var=loto82
# newvar is "loto8"
newvar=${var%[0-9]*}

Delete longest match of substring (from back)

var=loto82
# newvar is "loto"
newvar=${var%%[0-9]*}

Replace one occurrence of substring

var=test.test.test
# newvar is "T.test.test"
newvar=${var/test/T}

Replace all occurrences of substring

ar=test.test.test
# newvar is "T.T.T"
newvar=${var//test/T}

Replace prefix of the string

var=test.passed.test
# newvar is "T.passed.test"
newvar=${var/#test/T}

var=passed.test.test
# newvar is "passed.test.test"
newvar=${var/#test/T}

Replace suffix of the string

var=test.passed.test
# newvar is "test.passed.T"
newvar=${var/%test/T}

var=test.test.passed
# newvar is "test.test.passed"
newvar=${var/%test/T}

Get directory part of the path

fullpath=/usr/local/bin/bash
# dir is "/usr/local/bin"
dir=${fullpath%/*}

Get file part of the path

fullpath=/usr/local/bin/bash
# file is "bash"
file=${fullpath##*/}

Get extension part of the path

fullpath=/usr/local/X11/rgb.txt
# ext is "txt"
ext=${fullpath##*.}

Remove last extension from the filename

fullpath=/usr/local/X11/rgb.txt
# filenoext is "/usr/local/X11/rgb"
filenoext=${fullpath%.*}

Remove all extensions from the filename

fullpath=/usr/local/db/customers.tar.gz
# filenoexts is "/usr/local/db/customers"
filenoexts=${fullpath%%.*}

Capitalize first letter (bash 4)

var='one Two three'
# newvar is "One Two three" 
newvar=${var^}

Capitalize string (bash 4)

var='one Two three'
# newvar is "ONE TWO THREE" 
newvar=${var^^}

Lower case of the first letter (bash 4)

var='One Two three'
# newvar is "one Two three" 
newvar=${var,}

Lower case whole string (bash 4)

var='One Two Three'
# newvar is "one two three" 
newvar=${var,,}