美文网首页
shell 字符串拼接

shell 字符串拼接

作者: 数据小新手 | 来源:发表于2020-02-28 21:03 被阅读0次

字符串拼接

Shell 中你不需要使用任何运算符,将两个字符串并排放在一起就能实现拼接,非常简单粗暴。

#!/bin/bash
name="Shell"
url="http://c.biancheng.net/shell/"
str1=$name$url  #中间不能有空格
Shellhttp://c.biancheng.net/shell/

str2="$name $url"  #如果被双引号包围,那么中间可以有空格
Shell http://c.biancheng.net/shell/

str3=$name": "$url  #中间可以出现别的字符串
Shell: http://c.biancheng.net/shell/

str4="$name: $url"  #这样写也可以
Shell: http://c.biancheng.net/shell/

str5="${name}Script: ${url}index.html"  #这个时候需要给变量名加上大括号
ShellScript: http://c.biancheng.net/shell/index.html

相关文章

网友评论

      本文标题:shell 字符串拼接

      本文链接:https://www.haomeiwen.com/subject/jcirhhtx.html