Reverse each character case using bash script – Code Example


In this article I will provide you the code to reverse each character case in a string using bash script. Convert from uppercase to lowercase and vice versa. This code works on each character. For example – hElLo will get converted to HeLlO.

Code Example –


reverse_case() {
    echo "${1~~}"

reverse_case "AN animAl is aN animal. DONKEY or DOG does NoT mAtTeR"

# Output
# an ANIMaL IS An ANIMAL. donkey OR dog DOES nOt MaTtEr

Inspired from Dylan Araps

Live Demo

Open Live Demo