-2

I have written the code. to check the variable value if it GL then SQLGL should XDOAPPL, if AP then SQLAP should assign XDOAPPL variable. but it is giving me the error.

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
  • There are multiple syntax error in your code. Please run it though ShellCheck. – Kusalananda Mar 2 '18 at 8:11
  • 1
    “it is giving me the error” So copy-paste the error message into your question. – Gilles 'SO- stop being evil' Mar 2 '18 at 8:24
  • 1
    @DeclanGallagher I have rolled back your edit to the question. The whole point of this question lies in the syntax errors. Do not correct them. – Kusalananda Mar 2 '18 at 8:50
0

When using [[ ]], you must leave a space between [[ or ]] and the content. You also mistyped a } instead of a ] in the first if.

Here is the correct code :

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
|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.