uppercase first character in a variable with bash

前端 未结 15 1759
一整个雨季
一整个雨季 2020-12-04 07:01

I want to uppercase just the first character in my string with bash.

foo=\"bar\";

//uppercase first character

echo $foo;

should print \"B

15条回答
  •  生来不讨喜
    2020-12-04 07:30

    Not exactly what asked but quite helpful

    declare -u foo #When the variable is assigned a value, all lower-case characters are converted to upper-case.
    
    foo=bar
    echo $foo
    BAR
    

    And the opposite

    declare -l foo #When the variable is assigned a value, all upper-case characters are converted to lower-case.
    
    foo=BAR
    echo $foo
    bar
    

提交回复
热议问题