[asterisk-users] AEL question: testing channel variables
Steve Murphy
murf at digium.com
Thu Jan 8 12:36:33 CST 2009
On Thu, 2009-01-08 at 19:24 +0100, Klaus Darilion wrote:
> Hi!
>
> I use the following condition:
>
> if (${FOOBAR}=YES) {
> ...
> }
>
> The problem is, that if FOOBAR is not defined at all Asterisk generates
> a warning:
>
> WARNING[11982]: ast_expr2.fl:407 ast_yyerror: ast_yyerror(): syntax
> error: syntax error, unexpected '=', expecting $end; Input:
> =YES
>
>
> Of course I could use the following code, but this bloats up the code:
>
>
> if (${EXISTS(${FOOBAR})}) {
> if (${FOOBAR}=YES) {
> ...
> }
> }
>
>
> Is there another syntax to have nice looking code but avoid the warning?
Klaus--
The simplest I can think of is:
if ("${FOOBAR}"="YES") {
...
}
adding the quotes just makes it so if ${FOOBAR} evaluates to nothing,
then it will still end being a token, and you avoid the syntax error.
You have to keep in mind that by the time the $[ ... ] exprs are evaluated,
all ${..} constructs have been recursively evaluated away.
the wiki is a good reference for AEL2... (http://voip-info.org/wiki/view/Asterisk+AEL2
and there is a page of example snippets.
murf
>
> thanks
> klaus
--
Steve Murphy <murf at digium.com>
Digium
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3227 bytes
Desc: not available
Url : http://lists.digium.com/pipermail/asterisk-users/attachments/20090108/ae8c3ecd/attachment.bin
More information about the asterisk-users
mailing list