Shell字符串处理规律总结
发布时间:2020-12-15 16:54:54 所属栏目:安全 来源:网络整理
导读:字符处理几个特殊约定 #代表 截掉 开始 chaosbom @chaosbomPC :~ $ file= "thisfile.txt" chaosbom @chaosbomPC :~ $ echo ${ file #*.} txtchaosbom @chaosbomPC :~ $ echo ${ file #*i} sfile.txt %代表 截掉 结尾 chaosbom @chaosbomPC :~ $ file= "thisf
字符处理几个特殊约定#代表截掉开始 chaosbom@chaosbomPC:~$ file="thisfile.txt"
chaosbom@chaosbomPC:~$ echo ${file#*.}
txt
chaosbom@chaosbomPC:~$ echo ${file#*i}
sfile.txt
%代表截掉结尾 chaosbom@chaosbomPC:~$ file="thisfile.txt"
chaosbom@chaosbomPC:~$ echo ${file%e.*}
thisfil
chaosbom@chaosbomPC:~$ echo ${file%.*}
thisfile
//代表取所有(相对应未明确所有则是第一个) chaosbom@chaosbomPC:~$ file="thisfile.txt"
chaosbom@chaosbomPC:~$ echo ${file//i/I}
thIsfIle.txt
chaosbom@chaosbomPC:~$ echo ${file//i}
thsfle.txt
/a/b 表示符合模式a的字符串将被b字符串替换,不指定b字符串则是删除。 灵感来源: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容