Shell 操作符
Summary
Operator
定义 | 说明 | 举例 | 备注 |
---|---|---|---|
普通变量 | |||
$((运算式)) | result=$(((2+5)*5)) | ||
$[运算式] | result=$[(2+5)*5] | ||
`expr 运算式` | tmp=`expr 2 + 5` | 注意必须有空格 | |
result=`expr $tmp \* 5` | 注意*号要转义 | ||
Other | |||
if [ condition ] | if [ -e ./test.sh ] | 注意condition两侧有空格 |
Practice
#!/bin/bash
result=$(((2+5)*5))
echo "result = $result"
result=$[(2+5)*5]
echo "result = $result"
tmp=`expr 2 + 5`
result=`expr $tmp \* 5`
echo "result = $result"
[root@propel tmp]# ./test.sh
result = 35
result = 35
result = 35
#!/bin/bash
if [ -e ./test.sh ]
then
echo "existing...."
fi
[root@propel tmp]# ./test.sh
existing…