Thursday, August 6, 2009

How to convert a string to upper or lower case in bash?

How to convert a string to upper or lower case in bash?

Assuming tr is available on the system,

Convert the given argument into an all lower case string.

toLower() {
echo $1 | tr "[:upper:]" "[:lower:]"
}

Convert the given argument into an all lower case string.

toUpper() {
echo $1 | tr "[:lower:]" "[:upper:]"
}


(taken from: http://blog.spikesource.com/bashstringconversion.htm)

No comments:

Post a Comment