All the following commands work with a variable called $string.
'pattern' means bash pattern, or can also be an ordinary string:
- String length: ${#string}
- Extract a substring: ${string:position}
- Extract a substring, specifying length: ${string:position:length}
- Delete shortest match of substring from the beginning of string: ${string#substring}
- Delete shortest match of substring from the end of string: ${string%substring}
- Delete longest match of substring from the beginning of string: ${string##substring}
- Delete longest match of substring from the end of string: ${string%%substring}
- Find and replace first substring: ${string/pattern/replacement}
- Find and replace all substrings: ${string//pattern/replacement}
Thanks to TheGeekStuff