1、运算
使用双引号可以引用除字符$、·、\外的任何字符和字符串
[root@oracle11g ~]# ls
abc abc.txt anaconda-ks.cfg cal.txt Desktop find.sh install.log install.log.syslog
[root@oracle11g ~]# echo * //只显示文件, 不包含目录
abc abc.txt anaconda-ks.cfg cal.txt Desktop find.sh install.log install.log.syslog
[root@oracle11g ~]# echo $[ 2+8 ]
10
[root@oracle11g ~]# echo $[2+8]
10
[root@oracle11g ~]# echo $[ 2>>8 ] //将2向右移8位,左边补0
0
[root@oracle11g ~]# echo $[ 2<<4 ] //将2向左移4位,右边补0
32
[root@oracle11g ~]# echo $[ 2^4 ] //异或运算
6
[root@oracle11g ~]# echo $[ 2 | 4 ] //或运算
6
[root@oracle11g ~]# echo $[ ~3 ] //取反,将所有的二进制位1->0, 0->1
-4
abc abc.txt anaconda-ks.cfg cal.txt Desktop find.sh install.log install.log.syslog
[root@oracle11g ~]# echo * //只显示文件, 不包含目录
abc abc.txt anaconda-ks.cfg cal.txt Desktop find.sh install.log install.log.syslog
[root@oracle11g ~]# echo $[ 2+8 ]
10
[root@oracle11g ~]# echo $[2+8]
10
[root@oracle11g ~]# echo $[ 2>>8 ] //将2向右移8位,左边补0
0
[root@oracle11g ~]# echo $[ 2<<4 ] //将2向左移4位,右边补0
32
[root@oracle11g ~]# echo $[ 2^4 ] //异或运算
6
[root@oracle11g ~]# echo $[ 2 | 4 ] //或运算
6
[root@oracle11g ~]# echo $[ ~3 ] //取反,将所有的二进制位1->0, 0->1
-4
2、赋值运算
=、+=、-=、*=、、=、%=、&=、^=、!=、<<=、>>=
let count=$count+$change
let count+=$change
- [simpleanti@PLATQA136025 logs]$ var=100
- [simpleanti@PLATQA136025 logs]$ let var=$var+4
- [simpleanti@PLATQA136025 logs]$ echo $var
- 104
- [simpleanti@PLATQA136025 logs]$ let var+=5
- [simpleanti@PLATQA136025 logs]$ echo $var
- 109
3、表达式替换
[root@oracle11g ~]# echo $[
10#8 + 1 ] //8进制的10,在加上1, 即9
9
9
本文转自 tianya23 51CTO博客,原文链接:http://blog.51cto.com/tianya23/269777,如需转载请自行联系原作者