Convert String to Uppercase

To convert a string to uppercase in Bash, use tr command. tr stands for translate or transliterate. With tr command we can translate lowercase characters, if any, in the input string to uppercase characters.


The syntax to convert an input string to uppercase is

tr '[:lower:]' '[:upper:]'

tr command takes two two sets of characters as arguments.

With the above expression, if there are any lowercase characters in the given string, then tr converts it to uppercase.



In the following script, we take a string in s, and convert it to uppercase using tr command.

s="Hello World"
upperstr=$(echo $s | tr '[:lower:]' '[:upper:]')
echo "Original  String : $s"
echo "Uppercase String : $upperstr"


Original  String : Hello World
Uppercase String : HELLO WORLD


In this Bash Tutorial, we have learnt how to convert a string to uppercase in Bash Script using tr command.