Linux中字符串的拼接与截取
001、 字符串的拼接1
(base) [root@PC1 test2]# a=sample (base) [root@PC1 test2]# b=abc (base) [root@PC1 test2]# echo ${a}${b} sampleabc (base) [root@PC1 test2]# echo ${a}_${b} sample_abc (base) [root@PC1 test2]# echo ${a}_${b}_ sample_abc_ (base) [root@PC1 test2]# echo ${a}_${b}_kkk sample_abc_kkk

.
002、循环拼接
(base) [root@PC1 test2]# echo ${a} sample (base) [root@PC1 test2]# for i in {01..05}; do echo ${a}_${i}; done ## 循环拼接 sample_01 sample_02 sample_03 sample_04 sample_05

。
003、字符串的截取
(base) [root@PC1 test2]# echo $a sample (base) [root@PC1 test2]# echo ${a:0:2} ## 截取前两个字符 sa (base) [root@PC1 test2]# echo ${a:0:4} samp (base) [root@PC1 test2]# echo ${a:2:2} ## 第二个字符后,截取两个 mp (base) [root@PC1 test2]# echo ${a:2:3} mpl (base) [root@PC1 test2]# echo ${a: -3} ## 截取后三个 ple (base) [root@PC1 test2]# echo ${a: -3:2} ## 后三个开始,截取两个 pl (base) [root@PC1 test2]# echo ${a:2} ## 截取第二个后开始,一直到最后 mple

。
