Bash (Scripting) - uppercase or lowercase (tr command)

by
Jeremy Canfield |
Updated: April 13 2023
| Bash (Scripting) articles
The tr (translate) command can be used to modify a string to be lowercase or uppercase. In this example, the string is modified to be lowercase.
~]# echo "Hello World" | tr '[:upper:]' '[:lower:]'
hello world
In this example, the string is modified to be uppercase.
~]# echo "Hello World" | tr '[:lower:]' '[:upper:]'
HELLO WORLD
In this example, a variable in a bash script is modified to be lowercase.
foo="Hello World"
foo=$(echo $foo | tr '[:upper:]' '[:lower:]')
Did you find this article helpful?
If so, consider buying me a coffee over at