uppercase first character in a variable with bash

前端 未结 15 1758
一整个雨季
一整个雨季 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:33

    Here is the "native" text tools way:

    #!/bin/bash
    
    string="abcd"
    first=`echo $string|cut -c1|tr [a-z] [A-Z]`
    second=`echo $string|cut -c2-`
    echo $first$second
    

提交回复
热议问题