bash中的test语句是使用方括号加分号括起来的,注意方括号与其中的条件之间要加空格。
http://imghch.com/doc/bk03ch03s04.html
亮点:
Example 3.9. 用 if-then-else 来计算表达式
[user@domain ~]$ function mycalc ()
> {
> local x
> if [ $# -lt 1 ]; then
> echo "This function evaluates arithmetic for you if you give it some"
> elif (( $* )); then
> let x="$*"
> echo "$* = $x"
> else
> echo "$* = 0 or is not an arithmetic expression"
> fi
> }
[user@domain ~]$ mycalc 3 + 4
3 + 4 = 7
[user@domain ~]$ mycalc 3 + 4**3
3 + 4**3 = 67
[user@domain ~]$ mycalc 3 + (4**3 /2)
-<application>Bash</application>: syntax error near unexpected token `('
[user@domain ~]$ mycalc 3 + "(4**3 /2)"
3 + (4**3 /2) = 35
[user@domain ~]$ mycalc xyz
xyz = 0 or is not an arithmetic expression
[user@domain ~]$ mycalc xyz + 3 + "(4**3 /2)" + abc
xyz + 3 + (4**3 /2) + abc = 35
HxLauncher: Launch Android applications by voice commands