1、變量
命名的內存空間
本地變量
生效范圍:當前shell進程
變量引用:${name}
環境變量
生效范圍: 當前shell進程以及子shell
(通過declare -x 或export 命令)
[root@fenfa ~]# declare -x name='test'
[root@fenfa ~]# echo $name
test
[root@fenfa ~]# bash--打開一個子shell
[root@fenfa ~]# echo $name
test
局部變量
生效范圍: 生效范圍為當前shell進程中某代碼片段
位置變量
$1,$2......,來表示,用于讓腳本在腳本代碼中調用
特殊變量
$? $0 $* $@ $#
2)bash中的算術運算
實現算術運算的方式:
let var=算術表達式
$[算術表達式 ]
$((算術表達式))
var=$(expr arg1 + arg3)
[root@fenfa scripts]# var=$(expr $num1 + $num2)