How to convert a string to lower case in Bash?

前端 未结 20 2021
慢半拍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:19

    Using GNU sed:

    sed 's/.*/\L&/'
    

    Example:

    $ foo="Some STRIng";
    $ foo=$(echo "$foo" | sed 's/.*/\L&/')
    $ echo "$foo"
    some string
    
    0 讨论(0)
  • 2020-11-22 10:20

    In bash 4 you can use typeset

    Example:

    A="HELLO WORLD"
    typeset -l A=$A
    
    0 讨论(0)
提交回复
热议问题