1. 字符串如何大小写转换
str="This is a Bash Shell script."
1> tr方式
newstr=`tr ‘[A-Z]‘ ‘[a-z]‘ <<<"$str"`或者 newstr=$(echo $str |tr ‘[a-z]‘ ‘[A-Z]‘)
2> typeset
typeset -u VARIABLE (把VARIABLE的小写转换成大写)
typeset -l VARIABLE (把VARIABLE的大写转换成小写)
如:
[[email protected] ~]$ typeset -u str
[[email protected] ~]$ str="This is a Bash Shell script."
[[email protected] ~]$ echo $str
THIS IS A BASH SHELL SCRIPT.
时间: 2024-10-07 10:21:36