linux/shell中大小写转换
# 大小写转换示例代码
#!/bin/bash rm -rf ./6.4.1.txt echo "abcdEfgHiJ" > ./6.4.1.txt File=`cat ./6.4.1.txt` TmpFile=${File} echo "number of target:$#" [ $1 != "-u" ] && [ $1 != "-i" ] && { echo "please use'-u'or'-i'"; exit -1; } echo "source str:${File}" [ $1 == "-u" ] && { echo ${File} |tr "[a-z]" "[A-Z]"| tee -a ./6.4.1.txt; } [ $1 == "-i" ] && { echo ${File,,}| tee -a ./6.4.1.txt; } # the second way lower to upper #[ $1 == "-i" ] && { echo ${File^^}; }
小写转大写
echo "abcd" |tr "[a-z]" "[A-Z]"
或
str="abcd"
echo ${str^^}
大写转小写
echo "abcd" |tr "[A-Z]" "[a-z]" 或 str="abcd" echo ${str,,}