现在的位置: 首页 > 综合 > 正文

linux shell脚本犯错

2013年08月04日 ⁄ 综合 ⁄ 共 579字 ⁄ 字号 评论关闭
脚本里犯了错 --
[oracle@simpleit shell]$ value=1
[oracle@simpleit shell]$ value = 1
-bash: value: command not found
[oracle@simpleit shell]$ value = 3
-bash: value: command not found
[oracle@simpleit shell]$ echo value
value
[oracle@simpleit shell]$ echo "value"
value
[oracle@simpleit shell]$ echo $value
1
[oracle@simpleit shell]$ echo '$value'
$value
[oracle@simpleit shell]$ echo "$value"
1
[oracle@simpleit shell]$

shell脚本中给变量赋值  = 两边不能有空格。

[oracle@simpleit shell]$ value=4
[oracle@simpleit shell]$ [$value -gt 2]
-bash: [4: command not found
[oracle@simpleit shell]$ [ $value -gt 2 ]
[oracle@simpleit shell]$ echo $?
0

[  ]多数用于比较判断,注意[  ]中"["后要有一空格,"]"前也要有一空格 。

 

抱歉!评论已关闭.