Skip to content

Convert String to Lowercase in Bash – Easier Than You Think

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

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

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


Back to top