我已经写好了代码。检查变量值,如果是GL,那么SQLGL应该XDOAPPL,如果是AP,那么SQLAP应该分配XDOAPPL变量。但它给了我错误。
APPL=$1
x=AP
y=GL
echo "Value of x = $x and y = $y."
a=SQLAP
b=SQLGL
if [["$APPL" = "AP"]};
then
XDOAPPL=${a}
echo "AP XDOAPPL =$XDOAPPL"
elif [["$APPL" = "GL"]];
then
XDOAPPL=${b}
echo "GL XDOAPPL =$XDOAPPL"
else
echo "Nothing to go"
fi
答案1
使用 时,或与内容[[ ]]
之间必须留有空格。您还在第一个中错误地输入了 a而不是 a 。[[
]]
}
]
if
这是正确的代码:
APPL=$1
x=AP
y=GL
echo "Value of x = $x and y = $y."
a=SQLAP
b=SQLGL
if [[ "$APPL" = "AP" ]];
then
XDOAPPL=${a}
echo "AP XDOAPPL = $XDOAPPL"
elif [[ "$APPL" = "GL" ]];
then
XDOAPPL=${b}
echo "GL XDOAPPL = $XDOAPPL"
else
echo "Nothing to go"
fi