How to convert a string to lower case in Bash?

前端 未结 20 2422
慢半拍i
慢半拍i 2020-11-22 09:40

Is there a way in bash to convert a string into a lower case string?

For example, if I have:

a=\"Hi all\"

I want to convert it to:<

20条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 10:00

    Converting case is done for alphabets only. So, this should work neatly.

    I am focusing on converting alphabets between a-z from upper case to lower case. Any other characters should just be printed in stdout as it is...

    Converts the all text in path/to/file/filename within a-z range to A-Z

    For converting lower case to upper case

    cat path/to/file/filename | tr 'a-z' 'A-Z'
    

    For converting from upper case to lower case

    cat path/to/file/filename | tr 'A-Z' 'a-z'
    

    For example,

    filename:

    my name is xyz
    

    gets converted to:

    MY NAME IS XYZ
    

    Example 2:

    echo "my name is 123 karthik" | tr 'a-z' 'A-Z'
    # Output:
    # MY NAME IS 123 KARTHIK
    

    Example 3:

    echo "my name is 123 &&^&& #@$#@%%& kAR2~thik" | tr 'a-z' 'A-Z'
    # Output:
    # MY NAME IS 123 &&^&& #@0@%%& KAR2~THIK
    

提交回复
热议问题