Linux Shell编程(二)

目录

字符串

1)"" 这种形式的双引号里面可以使用  ${}  或者 $  去引用变量

1--通过${}引用

2--通过$引用

2)''这种形式的单引号里面,会导致${} 和 $变量名会失效


字符串

字符串分为 ""  和  '' 两种形式

1)"" 这种形式的双引号里面可以使用  ${}  或者 $  去引用变量

1--通过${}引用

[xijiu@localhost ~]$ student="tou zhou wan xia de ren"
[xijiu@localhost ~]$ echo $student
tou zhou wan xia de ren
[xijiu@localhost ~]$ studentClass="三班${student}"
[xijiu@localhost ~]$ echo studentClass
studentClass
[xijiu@localhost ~]$ echo $studentClass
三班tou zhou wan xia de ren

2--通过$引用

注意:$引用必须是用空格把变量名隔开

[xijiu@localhost ~]$ student2="xi.ji"
[xijiu@localhost ~]$ echo $student
tou zhou wan xia de ren
[xijiu@localhost ~]$ echo $student2
xi.ji
[xijiu@localhost ~]$ studentClass2="三班:$student2"
[xijiu@localhost ~]$ echo studentClass2
studentClass2
[xijiu@localhost ~]$ echo ${studentClass2}
三班:xi.ji
[xijiu@localhost ~]$ 

变量名没有隔开

[xijiu@localhost ~]$ studentCLass3="三班:$student2student"
[xijiu@localhost ~]$ echo $studentClass3

[xijiu@localhost ~]$ echo $studentClass3

[xijiu@localhost ~]$ 

2)''这种形式的单引号里面,会导致${}  $变量名会失效

[xijiu@localhost ~]$ fruitOne="apple"
[xijiu@localhost ~]$ MyLoveFruit='我喜欢的水果是:${fruitOne}'
[xijiu@localhost ~]$ echo MyLoveFruit
MyLoveFruit
[xijiu@localhost ~]$ echo $MyLoveFruit
我喜欢的水果是:${fruitOne}
[xijiu@localhost ~]$ MyLoveFruit='我喜欢的水果是:$fruitOne'
[xijiu@localhost ~]$ echo $MyLoveFruit
我喜欢的水果是:$fruitOne
[xijiu@localhost ~]$ 


可以看到,${}和$ 的引用均失效了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值