1. 小写转大写
1. 1 全部转换成大写
${str^^}
$ ls
00-RELEASENOTES COPYING Makefile deps runtest-cluster sentinel.conf utils
BUGS INSTALL README.md redis.conf runtest-moduleapi src
CONTRIBUTING MANIFESTO TLS.md runtest runtest-sentinel tests
$ for name in *;do echo ${name^^} ;done
00-RELEASENOTES
BUGS
CONTRIBUTING
COPYING
INSTALL
MANIFESTO
MAKEFILE
README.MD
TLS.MD
DEPS
REDIS.CONF
RUNTEST
RUNTEST-CLUSTER
RUNTEST-MODULEAPI
RUNTEST-SENTINEL
SENTINEL.CONF
SRC
TESTS
UTILS
echo str | tr 'a-z' 'A-Z'
$ ls
00-RELEASENOTES COPYING Makefile deps runtest-cluster sentinel.conf utils
BUGS INSTALL README.md redis.conf runtest-moduleapi src
CONTRIBUTING MANIFESTO TLS.md runtest runtest-sentinel tests
$ for name in *;do echo $name | tr 'a-z' 'A-Z' ;done
00-RELEASENOTES
BUGS
CONTRIBUTING
COPYING
INSTALL
MANIFESTO
MAKEFILE
README.MD
TLS.MD
DEPS
REDIS.CONF
RUNTEST
RUNTEST-CLUSTER
RUNTEST-MODULEAPI
RUNTEST-SENTINEL
SENTINEL.CONF
SRC
TESTS
UTILS
declare -u 变量
bash4 或更高版本
通过声明变量类型,赋值时自动转换
$ bash --version
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
$ ls
00-RELEASENOTES COPYING Makefile deps runtest-cluster sentinel.conf utils
BUGS INSTALL README.md redis.conf runtest-moduleapi src
CONTRIBUTING MANIFESTO TLS.md runtest runtest-sentinel tests
$ declare -u UPV;for name in *;do UPV=$name;echo $UPV;done
00-RELEASENOTES
BUGS
CONTRIBUTING
COPYING
INSTALL
MANIFESTO
MAKEFILE
README.MD
TLS.MD
DEPS
REDIS.CONF
RUNTEST
RUNTEST-CLUSTER
RUNTEST-MODULEAPI
RUNTEST-SENTINEL
SENTINEL.CONF
SRC
TESTS
UTILS
$
1.2 首字符转换成大写
${str^}
$ ls
00-RELEASENOTES COPYING Makefile deps runtest-cluster sentinel.conf utils
BUGS INSTALL README.md redis.conf runtest-moduleapi src
CONTRIBUTING MANIFESTO TLS.md runtest runtest-sentinel tests
$ for name in *;do echo ${name^} ;done
00-RELEASENOTES
BUGS
CONTRIBUTING
COPYING
INSTALL
MANIFESTO
Makefile
README.md
TLS.md
Deps
Redis.conf
Runtest
Runtest-cluster
Runtest-moduleapi
Runtest-sentinel
Sentinel.conf
Src
Tests
Utils
1.3 仅首字符大写
declare -c 变量
bash4 或更高版本
通过声明变量类型,赋值时自动转换
$ bash --version
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
$ ls
00-RELEASENOTES COPYING Makefile deps runtest-cluster sentinel.conf utils
BUGS INSTALL README.md redis.conf runtest-moduleapi src
CONTRIBUTING MANIFESTO TLS.md runtest runtest-sentinel tests
$ declare -c Upv;for name in *; do Upv=$name;echo $Upv;done
00-releasenotes
Bugs
Contributing
Copying
Install
Manifesto
Makefile
Readme.md
Tls.md
Deps
Redis.conf
Runtest
Runtest-cluster
Runtest-moduleapi
Runtest-sentinel
Sentinel.conf
Src
Tests
Utils
2. 大写转小写
2. 1 全部转换成小写
${str,,}
$ ls
00-RELEASENOTES COPYING Makefile deps runtest-cluster sentinel.conf utils
BUGS INSTALL README.md redis.conf runtest-moduleapi src
CONTRIBUTING MANIFESTO TLS.md runtest runtest-sentinel tests
$ for name in *;do echo ${name,,};done
00-releasenotes
bugs
contributing
copying
install
manifesto
makefile
readme.md
tls.md
deps
redis.conf
runtest
runtest-cluster
runtest-moduleapi
runtest-sentinel
sentinel.conf
src
tests
utils
echo str | tr 'A-Z' 'a-z'
$ ls
00-RELEASENOTES COPYING Makefile deps runtest-cluster sentinel.conf utils
BUGS INSTALL README.md redis.conf runtest-moduleapi src
CONTRIBUTING MANIFESTO TLS.md runtest runtest-sentinel tests
$ for name in *; do echo $name | tr 'A-Z' 'a-z'; done
00-releasenotes
bugs
contributing
copying
install
manifesto
makefile
readme.md
tls.md
deps
redis.conf
runtest
runtest-cluster
runtest-moduleapi
runtest-sentinel
sentinel.conf
src
tests
utils
declear -l 变量
bash4 或更高版本
通过声明变量类型,赋值时自动转换
$ bash --version
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
$ ls
00-RELEASENOTES COPYING Makefile deps runtest-cluster sentinel.conf utils
BUGS INSTALL README.md redis.conf runtest-moduleapi src
CONTRIBUTING MANIFESTO TLS.md runtest runtest-sentinel tests
$ declare -l lowv;for name in *; do lowv=$name;echo $lowv; done
00-releasenotes
bugs
contributing
copying
install
manifesto
makefile
readme.md
tls.md
deps
redis.conf
runtest
runtest-cluster
runtest-moduleapi
runtest-sentinel
sentinel.conf
src
tests
utils
2.2 首字符转换成小写
${str,}
$ ls
00-RELEASENOTES COPYING Makefile deps runtest-cluster sentinel.conf utils
BUGS INSTALL README.md redis.conf runtest-moduleapi src
CONTRIBUTING MANIFESTO TLS.md runtest runtest-sentinel tests
$ for name in *; do echo ${name,}; done
00-RELEASENOTES
bUGS
cONTRIBUTING
cOPYING
iNSTALL
mANIFESTO
makefile
rEADME.md
tLS.md
deps
redis.conf
runtest
runtest-cluster
runtest-moduleapi
runtest-sentinel
sentinel.conf
src
tests
utils
3. 大小写互转
3.1 全部逆转
${str~~}
$ ls
00-RELEASENOTES COPYING Makefile deps runtest-cluster sentinel.conf utils
BUGS INSTALL README.md redis.conf runtest-moduleapi src
CONTRIBUTING MANIFESTO TLS.md runtest runtest-sentinel tests
$ for name in *; do echo ${name~~};done
00-releasenotes
bugs
contributing
copying
install
manifesto
mAKEFILE
readme.MD
tls.MD
DEPS
REDIS.CONF
RUNTEST
RUNTEST-CLUSTER
RUNTEST-MODULEAPI
RUNTEST-SENTINEL
SENTINEL.CONF
SRC
TESTS
UTILS
3.2 首字符逆转
${str~}
$ ls
00-RELEASENOTES COPYING Makefile deps runtest-cluster sentinel.conf utils
BUGS INSTALL README.md redis.conf runtest-moduleapi src
CONTRIBUTING MANIFESTO TLS.md runtest runtest-sentinel tests
$ for name in *; do echo ${name~};done
00-RELEASENOTES
bUGS
cONTRIBUTING
cOPYING
iNSTALL
mANIFESTO
makefile
rEADME.md
tLS.md
Deps
Redis.conf
Runtest
Runtest-cluster
Runtest-moduleapi
Runtest-sentinel
Sentinel.conf
Src
Tests
Utils