[20180131]bash变量替换与截取.txt
--//bash编程经常用到变量替换与截取,经常记不住,做一些例子说明:
$ a=1a1b1c1d
$ echo $a
1a1b1c1d
$ echo ${a##*1}
d
$ echo ${a#*1}
a1b1c1d
--// ## 最长匹配替换 # 最短匹配替换
$ echo ${a%1*}
1a1b1c
$ echo ${a%%1*}
$ echo ${a%%c*}
1a1b1
--// %% 表示从尾部开始最长匹配替换 % 表示从尾部开始最短匹配替换
$ echo ${a/1/|}
|a1b1c1d
$ echo ${a//1/|}
|a|b|c|d
--// /替换1次 //全局替换 注意后面没有斜线.
$ echo -e ${PATH//:/\\n}
/u01/app/oracle/product/11.2.0.4/dbhome_1/jdk/bin
/usr/bin
/u01/app/oracle/product/11.2.0.4/dbhome_1/jdk/bin
/usr/bin
/usr/kerberos/bin
/usr/local/bin
/bin
/usr/bin
/usr/NX/bin
/home/oracle/bin
/u01/app/oracle/product/11.2.0.4/dbhome_1/bin
/home/oracle/anysql
/usr/NX/bin
/home/oracle/bin
/u01/app/oracle/product/11.2.0.4/dbhome_1/bin
/home/oracle/anysql
--//实际上bash还有许多功能,这些实际平时不用,实在记不住...