字符串拼接
在 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
网友评论