LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   A question about "echo "$CALLER" | tr -s '[:upper:]' '[:lower:]'" (https://www.linuxquestions.org/questions/linux-software-2/a-question-about-echo-%24caller-%7C-tr-s-%5B-upper-%5D-%5B-lower-%5D-934216/)

thomas2004ch 03-13-2012 08:01 AM

A question about "echo "$CALLER" | tr -s '[:upper:]' '[:lower:]'"
 
Hi all,

Als I run following command:
Code:

echo "EA" | tr -s  '[:upper:]'  '[:lower:]'
I got ea. This is correct. But as I run
Code:

echo "AA" | tr -s  '[:upper:]'  '[:lower:]'
I just got a.

How can I get the aa as return?

Guttorm 03-13-2012 08:23 AM

From "man tr":

Quote:

-s, --squeeze-repeats
replace each input sequence of a repeated character that is listed in SET1 with a single occurrence of that character
So drop the -s option.

MensaWater 03-13-2012 08:26 AM

Don't use "-s" - it tells it to get rid of repeats so it doesn't show the second "a". (You'd have same issue with EE, FF, ZZ etc... using "-s".

Code:

echo "AA" |tr '[:upper:]' '[:lower:]'

H_TeXMeX_H 03-13-2012 08:39 AM

EDIT: What they said, I posted late.

thomas2004ch 03-13-2012 09:03 AM

Quote:

Originally Posted by H_TeXMeX_H (Post 4625691)
EDIT: What they said, I posted late.

:-)

David the H. 03-13-2012 02:57 PM

BTW, bash v4+ has case conversion parameter substitutions built-in.

Code:

string="ABCDE"
echo "${string,,}"

You can also declare a variable to be only upper or lower case.


All times are GMT -5. The time now is 02:53 AM.