Klaus Darilion
2009-Jan-08 18:24 UTC
[asterisk-users] AEL question: testing channel variables
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? thanks klaus
Julian Lyndon-Smith
2009-Jan-08 18:30 UTC
[asterisk-users] AEL question: testing channel variables
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? >How about if ("${FOOBAR}"="YES") { Julian> thanks > klaus > > _______________________________________________ > -- Bandwidth and Colocation Provided by http://www.api-digital.com -- > > asterisk-users mailing list > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users > >______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________
Steve Murphy
2009-Jan-08 18:36 UTC
[asterisk-users] AEL question: testing channel variables
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
Brent Vrieze
2009-Jan-08 18:41 UTC
[asterisk-users] AEL question: testing channel variables
Initialize FOOBAR to some know value (ie NO) and change it when you need to. Then it will always be defined. 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? > > thanks > klaus > > _______________________________________________ > -- Bandwidth and Colocation Provided by http://www.api-digital.com -- > > asterisk-users mailing list > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users > > >
Philipp Kempgen
2009-Jan-10 18:53 UTC
[asterisk-users] AEL question: testing channel variables
Klaus Darilion schrieb:> 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?if ("${FOOBAR}"="YES") { ... } or if (x${FOOBAR}=xYES) { ... } Philipp Kempgen -- AMOOCON 2009, May 4-5, Rostock / Germany -> http://www.amoocon.de Asterisk: http://the-asterisk-book.com - http://das-asterisk-buch.de AMOOMA GmbH - Bachstr. 126 - 56566 Neuwied -> http://www.amooma.de Gesch?ftsf?hrer: Stefan Wintermeyer, Handelsregister: Neuwied B14998 --