Convert a string to lowercase in Bash

Here are the top 3 ways for converting a string to lowercase in Bash.

Using tr

One of the most popular ways for lowercasing a string is using tr. This is a POSIX standard method for accomplishing the task.

1
2
echo "I WANT this LoWeRcAsEd" | tr '[:upper:]' '[:lower:]'
# Outputs: i want this lowercased

Using awk

Another POXIS standard is using awk’s native toLower method.

1
2
echo "I WANT this LoWeRcAsEd" | awk '{print tolower($0)}'
# Outputs: i want this lowercased

Using Bash 4.0

bash 4.0 natively supports converting strings to lowercase.

1
2
3
toLower="I WANT this LoWeRcAsEd"
echo "${toLower,,}"
# Outputs: i want this lowercased