4,字符串拼接和运算符

字符串拼接

创建str.sh,内容如下:

name="tom"
url="www.baidu.com"

str1=$name$url #中间不能有空格

str2="$name $url" #如果被双引号包裹,那么中间是可以有空格

str3=$name"--->"$url #中间可以出现别的字符串

str4="$name--->$url" #也可以这样写
str5="${name}:${url}/aaa" #这个时候需要给变量名加上大括号

str6='${name}' #单引号原样输出

echo $str1

echo $str2
echo $str3
echo $str4
echo $str5
echo $str6
echo end

运行输出

[root@jenkins ~]# chmod +x str.sh
[root@jenkins ~]# ./str.sh
tomwww.baidu.com
tom www.baidu.com
tom--->www.baidu.com
tom--->www.baidu.com
tom:www.baidu.com/aaa
${name}
end
[root@jenkins ~]#

##运算符

语法

$((运算式))或者是$[运算式]

案例

[root@jenkins ~]# r=$((2+4+7))
[root@jenkins ~]# echo r
r
[root@jenkins ~]# echo $r
13
[root@jenkins ~]# r=$[1+2*3]
[root@jenkins ~]# echo $r
7
[root@jenkins ~]# r=$[(1+2)*5]
[root@jenkins ~]# echo $r
15
[root@jenkins ~]# echo $[10%4]
2
[root@jenkins ~]#
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值