Question :
I have the following code:
RESPOSTA=$(asterisk -rx "sip show peers" |grep 4003 |awk -F" " '{print $6}')
if[["$RESPOSTA" == "OK"]];then
echo $RESPOSTA
elif[["$RESPOSTA" == "Unmonitored"]];then
if[["$RESPOSTA" == "(Unspecified)"]]; then
cp /dados/automatico.call /var/spool/asterisk/outgoing/
asterisk -rx reload
fi
echo $RESPOSTA
fi
But it is generating this error:
/dates/status.sh: line 5: syntax error near unexpected token
then'
if [[“$ RESPONSE” == “OK”]]; then ‘
/dados/status.sh: line 5:
Answer :
Your corrected script:
RESPOSTA=$(asterisk -rx "sip show peers" |grep 4003 |awk -F" " '{print $6}')
if [[ "$RESPOSTA" = "OK" ]]; then
echo "$RESPOSTA"
elif [[ "$RESPOSTA" == "Unmonitored" ]]; then
if [[ "$RESPOSTA" == "(Unspecified)" ]]; then
cp /dados/automatico.call /var/spool/asterisk/outgoing/
asterisk -rx reload
fi
echo "$RESPOSTA"
fi
You had to put a space before and after [[
and ]]
.
Note: To analyze syntax problems online use this tool .
Shell is a weird programming language. Technically, [[
is not a deprecated element, but in fact it is a command that needs to be separated from its arguments using spaces. Try rewriting your ifs in this format:
if [[ "$RESPOSTA" == "OK" ]]; then