linux 中实现字符串的拼接

 

001、简单测试

[root@pc1 test01]# str1=ab          ## 测试字符串
[root@pc1 test01]# str2=xy
[root@pc1 test01]# echo $str1       ## 测试字符串
ab
[root@pc1 test01]# echo $str2
xy
[root@pc1 test01]# str3="$str1 $str2"    ## 字符串拼接
[root@pc1 test01]# echo $str3            ## 拼接效果
ab xy

 

002、循环拼接

[root@pc1 test01]# echo $str3
ab xy
[root@pc1 test01]# for i in {1..5}; do str3="$str3 $i"; done    ## 循环拼接
[root@pc1 test01]# echo $str3                                   ## 拼接效果
ab xy 1 2 3 4 5

 。

 

posted @ 2023-12-12 14:46  小鲨鱼2018  阅读(687)  评论(0编辑  收藏  举报