Strings

Change case, cut, replace and trim text with parameter expansion, split on a delimiter, and match with =~.

Runs in Zerethon IDE · Bash 5.2 Official Bash documentation ↗
main.sh
name="Ada Lovelace"
echo "$name has ${#name} characters"
echo "${name^^} ${name,,} ${name:0:3}"
trimmed=$(sed 's/^ *//; s/ *$//' <<< "  padded  ")
echo "$trimmed|"
IFS=, read -ra parts <<< "a,b,c"
echo "${parts[1]} ${#parts[@]}"
echo "${name/Ada/Augusta}"

file="report.final.txt"
echo "${file%.*} ${file##*.} ${file%%.*}"
[[ $name == Ada* ]] && echo "starts with Ada"

text="Order 12 shipped"
if [[ $text =~ ([0-9]+) ]]; then
  echo "number: ${BASH_REMATCH[1]}"
fi
printf '%.2f %5d %03d\n' 3.14159 42 7

Output

Ada Lovelace has 12 characters
ADA LOVELACE ada lovelace Ada
padded|
b 3
Augusta Lovelace
report.final txt report
starts with Ada
number: 12
3.14    42 007
  • ${var/old/new} replaces the first match, ${var//old/new} every match.
  • ${var%pattern} cuts the shortest match from the end, %% the longest; # and ## cut from the start — the usual way to get a file's name or extension.
  • <<< "text" (a here-string) gives a command that text as its input.
  • In [[ $x =~ regex ]] do not quote the regex; the capture groups are in BASH_REMATCH.