[Shell Script](EN) Convert between upper case letter and lower case letter

Post about converting between upper case letter and lower case letter in shell script(bash)


Environment and Prerequisite

  • Shell Script
  • Bash


Convert

Upper case -> Lower case

  • POSIX standard
test="THIS is TeSt"
echo "$test" | tr '[:upper:]' '[:lower:]'
  • Bash over 4.0
test="THIS is TeSt"
echo "${test,,}"

Lower case -> Upper case

  • POSIX standard
test="THIS is TeSt"
echo "$test" | tr '[:lower:]' '[:upper:]'
  • Bash over 4.0
test="THIS is TeSt"
echo "${test^^}"


Reference