linux 中字符串处理函数 ${i%%.*}

发布时间 2023-09-20 18:04:49作者: 小鲨鱼2018

 

001、

[root@pc1 test2]# ls
[root@pc1 test2]# str1="ab.cd_kk.mn_jjy"     ## 测试字符串
[root@pc1 test2]# echo ${str1%%.*}           ## 从左侧开始,删除.号右侧所有的内容
ab
[root@pc1 test2]# echo ${str1%.*}             ##从左侧开始, 删除最后一个.右侧的内容
ab.cd_kk

 

002、同上

[root@pc1 test2]# ls
[root@pc1 test2]# str1="ab.cd_kk.mn_jjy"
[root@pc1 test2]# echo ${str1%%_*}
ab.cd
[root@pc1 test2]# echo ${str1%_*}
ab.cd_kk.mn

 。