Skip to content

Convert String to Lowercase in Bash – Easier Than You Think

Advertisement

Question: How do I convert all the characters to the lowercase of a string in the bash shell script?

In Linux, the tr command is used to translate, squeeze, and/or delete characters. So with the help of the tr command, you can convert the case of any character. You can do this quickly with a single-line command.

You can use the following command to convert a string to lowercase. Here the command takes the standard input of a string and processes it.

echo "Input string here" | tr '[:upper:]' '[:lower:]' 

Let’s discuss with an example.

Example

Let’s create a sample shell script. Initialize a variable with a string having a few uppercase letters. Then convert all the letters to lowercase and store them in another variable.

Run the above script and see the results:

Output:
Input String: Hello World Result String: hello world

You can see the result string has all the characters in lowercase.

Rahul

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top