KSH 条件错误
KSH Conditional error
我花了 24 小时试图弄清楚谁可以在 KSH 中执行带参数的 If 语句。
我的脚本是:
VAR=failed
if [[ -gt ]];then
$VAR=Success
fi
echo $VAR
我得到的输出是
$FooBar.ksh 3 1
FooBar.ksh[2]: [[3: not found
failed
始终在 test 周围放置空格,所以 :
VAR=failed
if [[ -gt ]]; then
VAR='Success'
fi
echo "$VAR"
并且没有 $
sigil 当你给变量赋值时
一些测试
% ksh script.ksh 1 2
failed
% ksh script.ksh 2 1
Success
总是引用你的变量
"Double quote" 每个包含 spaces/metacharacters 和 每个 扩展的文字:"$var"
、"$(command "$var")"
、"${array[@]}"
, "a & b"
。使用 'single quotes'
作为代码或文字 $'s: 'Costs US'
、ssh host 'echo "$HOSTNAME"'
。参见
http://mywiki.wooledge.org/Quotes
http://mywiki.wooledge.org/Arguments
http://wiki.bash-hackers.org/syntax/words
最后一件事
避免对简单的脚本变量使用大写,为系统变量保留这些
我花了 24 小时试图弄清楚谁可以在 KSH 中执行带参数的 If 语句。
我的脚本是:
VAR=failed
if [[ -gt ]];then
$VAR=Success
fi
echo $VAR
我得到的输出是
$FooBar.ksh 3 1
FooBar.ksh[2]: [[3: not found
failed
始终在 test 周围放置空格,所以 :
VAR=failed
if [[ -gt ]]; then
VAR='Success'
fi
echo "$VAR"
并且没有 $
sigil 当你给变量赋值时
一些测试
% ksh script.ksh 1 2
failed
% ksh script.ksh 2 1
Success
总是引用你的变量
"Double quote" 每个包含 spaces/metacharacters 和 每个 扩展的文字:"$var"
、"$(command "$var")"
、"${array[@]}"
, "a & b"
。使用 'single quotes'
作为代码或文字 $'s: 'Costs US'
、ssh host 'echo "$HOSTNAME"'
。参见
http://mywiki.wooledge.org/Quotes
http://mywiki.wooledge.org/Arguments
http://wiki.bash-hackers.org/syntax/words
最后一件事
避免对简单的脚本变量使用大写,为系统变量保留这些