[Code Example] Reverse each character case using bash script

Total
0
Shares

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 –

#!/bin/bash

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

Demo might not work in private window (incognito)

Sign Up for Our Newsletters

Get only the best articles delivered to your mail

You May Also Like