[asterisk-users] BUG or ???

A J Stiles asterisk_list at earthshod.co.uk
Mon Feb 27 03:44:57 CST 2017


On Saturday 25 Feb 2017, Антон Сацкий wrote:
> Thanks U Richard
> i know about this solution
> but the main question why "${} substitution containing
> the SHELL is evaluated before anything else"

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.

> Can U describe the rules   when and  why it happens?

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).

-- 
AJS

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



More information about the asterisk-users mailing list