APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

case conversion in bash script??

Got questions? Go ahead: Ask me anything!

Author: anonymous
Date: Wed Aug 16 07:34:38 2006
Subject: case conversion in bash script??

I am writing a bash script.

Lets say,


Now I want to convert the content of VAR ($VAR) to lowercase. How can I do in bash.

i.e if I echo $VAR, I should get 'rakesh' not 'Rakesh'

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> case conversion in bash script??


Increase ad revenue 50-250% with Ezoic

More Articles by © anonymous

Wed Aug 16 09:59:26 2006: 2397   TonyLawrence

new=`echo $old | tr '[A-Z' '[a-z]'`

In other words, it has nothing to do with Bash: you could do this in any shell that allows backtick or some other way to accept the output of external cammands.

new=$(echo $old | tr '[A-Z' '[a-z]')

is a "Bash" solution, but the work is still done by "tr".

Wed Aug 16 13:25:15 2006: 2398   anonymous

One can also use awk for the same:-

new = echo $old | awk '{print tolower($0)}'


Mon Jun 8 07:10:38 2009: 6466   anonymous

little correction
new=$(echo $old | tr '[A-Z]' '[a-z]')
you missed the ']'

Kerio Samepage

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

If Linux can skate by the patent and copyright issues, its growth in the corporate world will continue no matter what business dislikes about the GPL. (Tony Lawrence)

This post tagged: