How to convert a string to lowercase in Bash
Overview
In this shot, we'll learn how to convert a string to lowercase in Bash. We'll use the tr command to achieve this. The command tr stands for translate.
Syntax
echo "Provide your string here" | tr '[:upper:]' '[:lower:]'
Parameters
The tr command accepts two sets of characters. We provide the first set as [:upper:] and the second set as [:lower:] so tr will replace the uppercase characters with lowercase characters.
Let's take a look at an example.
Example
echo "HELLO FROM EDUCATIVE !!!" | tr '[:upper:]' '[:lower:]'
Explanation
In the code snippet above, we convert the uppercase string HELLO FROM EDUCATIVE !!! to lowercase hello from educative !!! using the tr command.
echo "HELLO FROM EDUCATIVE !!!" | tr 'A-Z' 'a-z'
Explanation
We can also pass A-Z as the first set and a-z as the second test to convert a string to lowercase.