使用tr
toFirstLetterUpper(){
str=$1
firstLetter=${str:0:1}
otherLetter=${str:1}
firstLetter=$(echo $firstLetter | tr '[a-z]' '[A-Z]')
result=$firstLetter$otherLetter
}
toFirstLetterUpper1(){
str=$1
firstLetter=${str:0:1}
otherLetter=${str:1}
firstLetter=$(echo $firstLetter | tr '[:lower:]' '[:upper:]')
result=$firstLetter$otherLetter
}
使用awk
toFirstLetterUpper2() {
str=$1
firstLetter=`echo ${str:0:1} | awk '{print toupper($0)}'`
otherLetter=${str:1}
result=$firstLetter$otherLetter
}