首页 > 代码库 > Shell碎碎念

Shell碎碎念

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的大写转换成小写)

如:

[oracle@node3 ~]$ typeset -u str
[oracle@node3 ~]$ str="This is a Bash Shell script."
[oracle@node3 ~]$ echo $str
THIS IS A BASH SHELL SCRIPT.

 

Shell碎碎念