请坐!
一、变量的书写规范
变量格式
变量可以由字母、数字和下划线组成,但是不能以数字开头,变量中间不能有空格。
可以 _name
可以 name
但是不可以 2name
在Bash中,变量的默认类型都是字符串型,若要进行数值运算,必须修改变量类型为数值型。
[root@lx101 /sh]# x=666
[root@lx101 /sh]# y=777
[root@lx101 /sh]# s=$x+$y
[root@lx101 /sh]# echo $s
666+777
在进行变量赋值时,等号左右两侧不能有空格。
[root@lx101 /sh]# name =laox
-bash: name: command not found
[root@lx101 /sh]# name= laox
-bash: laox: command not found
[root@lx101 /sh]# name=laox
变量的值如果有空格,需要使用单引号或双引号包括。如:test=“hello world”。其中双引号内的符号“$”、“\”和反引号都拥有特殊含义,而单引号括起来的内容都是普通字符。
注意:单引号中任何字符都是普通字符,不具备任何特殊含义