You are not logged in.

#1 2013-07-26 11:49:02

oliver
Administrator
Registered: 2010-11-04
Posts: 2,209

bash and converting to upper or lower case

Sometimes I have a need to convert upper to lower case and vice-versa.  I had been piping things through /usr/bin/tr (part of coreutils) until I found this:

$ string="I wAnT tO cHaNgE tHe StRiNg CaSe"

$ echo ${string^^}
I WANT TO CHANGE THE STRING CASE

$ echo ${string,,}
i want to change the string case

$ echo ${string}
I wAnT tO cHaNgE tHe StRiNg CaSe

/usr/bin/tr still has it's uses... but this is much simpler.

I have a number of scripts that take user input so I'm using it to sanitize the input somewhat.

Offline

#2 2013-07-26 11:57:19

Mr Green
Administrator
Registered: 2010-11-07
Posts: 6,920

Re: bash and converting to upper or lower case


Comments, suggestions please feel free to contact me mrgreen(at)archbang(dot)org

Offline

Board footer

Powered by FluxBB