shell字符串大小写转换

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LLZK_/article/details/66972407

1、typeset 
有两个选项 -l 代表小写 -u 代表大写。
用法:
typeset -u name
name='asdasdas'
echo $name

typeset -l ame
ame='asdasdas'
echo $ame

结果:
[lzk@localhost 33_class_3_26_shell]$ bash test.sh
ASDASDAS
asdasdas


2、利用表达式

echo 'hello' | tr 'a-z' 'A-Z'
echo 'HELLO' | tr 'A-Z' 'a-z'
结果:

HELLO
hello

猜你喜欢

转载自blog.csdn.net/LLZK_/article/details/66972407