0.狂降
- 变量:1.标识符 2.数据类型
- 运算符:让多个变量产生关系
- 逻辑语句:1.顺序 2.分支 3.循环
- 方法/函数:将实现某一功能的代码封装
1.变量
-bash-4.2$ a=10
-bash-4.2$ b=20
-bash-4.2$ echo $a+$b
10+20
?2.shell字符串
- 单引号:任何字符串都会原样输出,变量无效
- 双引号:可以有变量以及转义字符
-bash-4.2$ name=haha
-bash-4.2$ echo $name
haha
-bash-4.2$ name2='xixi'
-bash-4.2$ echo $name2
xixi
-bash-4.2$ name3="heihei"
-bash-4.2$ echo $name3
heihei
-bash-4.2$ name4=$name 111
bash: 111: command not found...
-bash-4.2$ name4='$name 111'
-bash-4.2$ echo $name4
$name 111
-bash-4.2$ name5="$name 222"
-bash-4.2$ echo $name5
haha 222
-bash-4.2$ echo #$name5
-bash-4.2$ echo #{$name5}
-bash-4.2$ echo ${#name5}
8
- echo ${字符串名:N:M} 截取字符串N-M位
-bash-4.2$ echo ${name5:3:7}
a 222
?3.shell数组
- 数组的优点在于可以随机访问,链表的优势在于删减方便
- bash支持一维数组但不支持多维,没有限定数组的大小
- 数组定义用(),元素用空格符号分开
- 读取数组${数组名[下标]}
- 读取全部数组元素${数组名[@]}
- 获取数组长度还是用# ${#数组名[@]}
-bash-4.2$ s=(a b c d)
-bash-4.2$ echo ${s[2]}
c
-bash-4.2$ echo ${s[*]}
a b c d
-bash-4.2$ echo ${s[@]}
a b c d
-bash-4.2$ echo ${#s[*]}
4
|