Force string to be uppercase or lowercase in Bash

Home > Search
  by

The tr (trade) 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:])

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments