This tutorial covers how to convert a string to lower case in the bash script file.

For example, If the input string contains the “Hello World Welcome,” the output will be “hello world welcome.”

There are multiple ways to convert a string to lower case based on bash type and version.

  • using tr command

here is the syntax.

tr input_format output_format

Here is a shell script for converting to lower case

message="Hello World, Welcome."
echo "$message" | tr '[:upper:]' '[:lower:]'

Output:

hello world, welcome.

Another way to replace the above code

message="Hello World, Welcome."
echo "$message" | tr 'A-Z' 'a-z'

tr command works with ASCII and does not work with UTF characters.

  • using the awk command the string converts to lower case using the awk command tolower function combined with awk command to result in lower case string. The result is input to the echo command using the pipe operator.
message="Hello World, Welcome"
echo "$message" | awk '{print tolower($0)}'

This is best that works with ASCII and UTF characters.

  • in bash 4.0 version bash 4.0 provides string inbuilt in manipulation utilities. Adding two commas to a string makes a string in lower case string.
message="Hello World, Welcome"
echo "${message,,}"
echo "${message}"
  • using Perl in bash script

print lc with Perl makes a string in lower case letters

echo "$message" | perl -ne 'print lc'