Converting lowercase to uppercase in shell script

后端 未结 4 1059
余生分开走
余生分开走 2020-12-22 10:34

I tried to convert a lowercase string to uppercase and assign it to a variable using the following code

The script is written in .tn extension

相关标签:
4条回答
  • 2020-12-22 10:56

    As @anubhava mentioned, if anyone is looking to convert a string to lower case using a native way

    $ str="BASH"
    $ echo ${str,,}
    bash
    
    0 讨论(0)
  • 2020-12-22 10:59

    This should work:

    $ y="Foo Bar Baz"
    $ y_up=$(tr '[A-Z]' '[a-z]' <<< $y)
    $ echo $y_up
    foo bar baz
    
    0 讨论(0)
  • BASH 4+ version has native way to convert sting to upper case:

    upperStr="${str^^}"
    
    0 讨论(0)
  • 2020-12-22 11:04

    Below Works, Try this.

    bash-3.2$echo lower to upper | tr '[:lower:]' '[:upper:]'
    LOWER TO UPPER  
    
    # To Save in the variable use below
    var=$(echo lower to upper | tr '[:lower:]' '[:upper:]')
    
    0 讨论(0)
提交回复
热议问题