1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| [root@hadoop100 shell]# A=99 [root@hadoop100 shell]# echo $A 99 [root@hadoop100 shell]# A=97 [root@hadoop100 shell]# echo $A 97 [root@hadoop100 shell]# unset A [root@hadoop100 shell]# echo $A
[root@hadoop100 shell]# readonly B=88 [root@hadoop100 shell]# echo $B 88 [root@hadoop100 shell]# B=66 -bash: B: 只读变量 [root@hadoop100 shell]# unset B -bash: unset: B: 无法反设定: 只读 variable [root@hadoop100 shell]# C=1+2 [root@hadoop100 shell]# echo $C 1+2
# 数值运算 [root@hadoop100 shell]# C=$((2+2)) [root@hadoop100 shell]# echo $C 4 [root@hadoop100 shell]# C=$[1+2] [root@hadoop100 shell]# echo $C 3
# 提升变量作用域 [root@hadoop100 shell]# D="hello ghost" [root@hadoop100 shell]# echo $D hello ghost [root@hadoop100 shell]# export D [root@hadoop100 shell]# ll 总用量 8 -rwxr-xr-x. 1 root root 31 12月 11 14:56 hello.txt -rwxr-xr-x. 1 root root 25 12月 11 15:21 test.sh [root@hadoop100 shell]# vim hello.txt [root@hadoop100 shell]# sh hello.txt hello world hello ghost
|