BUG Or ???

Home » Asterisk Users » BUG Or ???
Asterisk Users 3 Comments

Got a strange situation

… exten => h,2,ExecIf($[${CALLERID(num)} = ‘ ‘]?Set(var29=${SHELL(curl -X
POST –header “Content-Type: application/json” –header “Accept:
application/json” -d “{\”Phone\”: ${FROMEXTEN}, \”Source\”: \”asterisk\”}” ”

exten => h,3,NoOp(${var29})
exten => h,4,Macro(hangupcall,)
;–== end of [ext-queues] ==–;

so when i execute it got

— Executing [h@ext-queues:1] NoOp(“SIP/100-00000050”, “100”) in new stack
— Executing [h@ext-queues:2] ExecIf(“SIP/100-00000050”,
in new stack
— Executing [h@ext-queues:3] NoOp(“SIP/100-00000050”, “”) in new stack
— Executing [h@ext-queues:4] Macro(“SIP/100-00000050”, “hangupcall,”)
in new st

U can see that Execif = 0 = falce but somehow Shell ${SHELL(curl -X POST –header “Content-Type: application/json”
–header “Accept: application/json” -d “{\”Phone\”: ${FROMEXTEN},
\”Source\”: \”asterisk\”}” ”
executes and get answer from the server

i dont want it to be executed

Thanks list for your help

3 thoughts on - BUG Or ???

  • The Set isn’t being executed by the ExecIf. However the ${} substitution containing the SHELL is evaluated before anything else is examined. This isn’t a bug but the order of how things are evaluated. You will have to do what you want another way:

    same = n,GotoIf($[“${CALLERID(num)}” = “”]?skip)
    same = n,Set(var29=${SHELL(…)})
    same = n(skip),NoOp(${var29})


  • Thanks U Richard i know about this solution but the main question why “${} substitution containing the SHELL is evaluated before anything else”
    Can U describe the rules when and why it happens?

    2017-02-24 23:44 GMT+02:00 Richard Mudgett :

  • For the same reason why you do raising to powers before multiplications and divisions, and all those before you do additions and subtractions. It’s just a mathematical convention, agreed upon a long time ago and handed down verbatim from generation to generation ever since.

    The order goes something like this (this is from memory; check docs for definitive version):

    * ${} variable substitution / munging
    * $[] expression evaluation
    – () round brackets
    – – arithmetical negation
    – * / % multiply and divide
    – + – add and subtract
    – < = > and =~ comparison
    – ! and ~ NOT
    – && and & AND
    – !! and | ^ OR and EOR
    * ?: embedded IFELSE operator

    Since ${} has a higher priority than ?: then the contents of the ${SHELL …}
    expression will be evaluated *before* Asterisk decides whether to do the bit between the ? and the : or the bit after the : . (And the most deepest embedded ${FROMEXTEN} needs to be evaluated before the shell can even be spawned to deal with the command). Having performed the SHELL command and got a result for the ${}, it *then* begins dealing with the $[] expression.
    ${CALLERID(num)} is compared against the target. It’s found to be false
    (empty string or numeric zero), therefore the Set(var29=…) does *not*
    happen. But, thanks to operator precedence, Asterisk has *already* evaluated what it would have set var29 to *before* it decides not to set it.

    It is generally better to use a GotoIf() to skip past a step you don’t want done, rather than embed it into an ExecIf() . This is not the 1980s anymore, and the odd well-placed GOTO is perfectly OK (and I’d reckon, actually *more*
    readable than the circumlocution necessary to avoid using it).


    Note: Originating address only accepts e-mail from list! If replying off-
    list, change address to asterisk1list at earthshod dot co dot uk .