Shell

How to convert string to lower case

There are several ways to convert a string from uppercase to lowercase in Bash:

  1. Use tr:

    [tum@ezylinux ~]$ echo 'Hello World!' | tr '[:upper:]' '[:lower:]'
    
    hello world!
  2. Use awk:

    [tum@ezylinux ~]$ echo 'Hello World!' | awk '{print tolower($0)}'
    
    hello world!
  3. In Bash 4.0 or later, use the following:

    [tum@ezylinux ~]$ A='Hello World!'
    [tum@ezylinux ~]$ echo ${A,,}
    
    hello world!
  4. Use Perl:

    [tum@ezylinux ~]$ echo 'Hello World!' | perl -ne 'print lc'
    
    hello world!
EOF.← Back to articles