Shell 操作符

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…

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章