美文网首页shell脚本
shell首字母转换为大写

shell首字母转换为大写

作者: halapro_liu | 来源:发表于2019-12-01 12:41 被阅读0次

使用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
}

相关文章

网友评论

    本文标题:shell首字母转换为大写

    本文链接:https://www.haomeiwen.com/subject/duezwctx.html