Asterisk expressions with forward slashes

Sorry for the simple question, but I’ve been trying different ways of approaching this for half an hour and I must be missing something:

I have a variable that has a forward slash (/ symbol) in it. I need to use that variable to resolve the name of another variable.

In the example below, ${desiredpeer} is equal to SIP/ATAxLB2 -

I need to get the value of the variable {calledsubscriberheldSIP/ATAxLB2holder}. Usually, the way I would do this is by having an expression resolve to the variable name, like so: {[calledsubscriber{desiredpeer}holder]}

I’ve done this thousands of times before, but never with a forward slash in the expression apparently. When I do this in this scenario, I get a bunch of errors about (as below). Clearly, Asterisk thinks I am trying to do division when I am just trying to concatenate strings and resolve them.

I tried surrounding them with quotes (in some of the later examples below) in a few different ways, and I get close, but the quotes still upset the parser. I don’t see anything about forward slashes here: Parameter Quoting - Asterisk Project - Asterisk Project Wiki or any notes about them in the expression pages on the wiki: Expressions - Asterisk Project - Asterisk Project Wiki

What would be the proper way to resolve the variable name / escape the forward slash if necessary?

I also tried resolving the variables and concatenating separately in one step and then plugging into an expression, but this also fails.

[2021-02-01 14:45:31] WARNING[9094][C-00000ce3]: ast_expr2.y:1495 op_div: non-numeric argument
[Feb  1 14:45:31]     -- Executing [s@ATA-dial:117] Set("Local/28@from-internal-00000c52;2", "channel2=") in new stack
[2021-02-01 14:45:31] WARNING[9094][C-00000ce3]: ast_expr2.fl:470 ast_yyerror: ast_yyerror():  syntax error: syntax error, unexpected '<token>', expecting $end; Input:
calledsubscriberheld$\{desiredpeer}holder
                       ^
[2021-02-01 14:45:31] WARNING[9094][C-00000ce3]: ast_expr2.fl:474 ast_yyerror: If you have questions, please refer to https://wiki.asterisk.org/wiki/display/AST/Channel+Variables
[Feb  1 14:45:31]     -- Executing [s@ATA-dial:118] Set("Local/28@from-internal-00000c52;2", "channel2=") in new stack
[2021-02-01 14:45:31] WARNING[9094][C-00000ce3]: ast_expr2.y:1495 op_div: non-numeric argument
[Feb  1 14:45:31]     -- Executing [s@ATA-dial:119] Set("Local/28@from-internal-00000c52;2", "channel2=") in new stack
[2021-02-01 14:45:31] WARNING[9094][C-00000ce3]: ast_expr2.fl:470 ast_yyerror: ast_yyerror():  syntax error: syntax error, unexpected '<token>', expecting $end; Input:
calledsubscriberheld"SIP/ATAxLB1"holder
                    ^
[2021-02-01 14:45:31] WARNING[9094][C-00000ce3]: ast_expr2.fl:474 ast_yyerror: If you have questions, please refer to https://wiki.asterisk.org/wiki/display/AST/Channel+Variables
[Feb  1 14:45:31]     -- Executing [s@ATA-dial:120] Set("Local/28@from-internal-00000c52;2", "channel2=") in new stack
[Feb  1 14:45:31]     -- Executing [s@ATA-dial:121] Set("Local/28@from-internal-00000c52;2", "channel2=") in new stack
[2021-02-01 14:45:31] WARNING[9094][C-00000ce3]: ast_expr2.fl:470 ast_yyerror: ast_yyerror():  syntax error: syntax error, unexpected '<token>', expecting $end; Input:
"calledsubscriberheld""SIP/ATAxLB1""holder""
                      ^
[2021-02-01 14:45:31] WARNING[9094][C-00000ce3]: ast_expr2.fl:474 ast_yyerror: If you have questions, please refer to https://wiki.asterisk.org/wiki/display/AST/Channel+Variables
[Feb  1 14:45:31]     -- Executing [s@ATA-dial:122] Set("Local/28@from-internal-00000c52;2", "channel2=") in new stack
[Feb  1 14:45:31]     -- Remote UNIX connection
[Feb  1 14:45:31]     -- Remote UNIX connection disconnected
[Feb  1 14:45:31]     -- Executing [s@ATA-dial:123] Set("Local/28@from-internal-00000c52;2", "redirect2=Usage: confbridge kick <conference> <channel>
[Feb  1 14:45:31]     --        Kicks a channel out of the conference bridge.
[Feb  1 14:45:31]     --              (all to kick everyone, participants to kick non-admins).
[Feb  1 14:45:31]     -- ") in new stack
same => n,Set(channel2=${$[calledsubscriberheld${desiredpeer}holder]})
same => n,Set(channel2=${$[calledsubscriberheld$\{desiredpeer}holder]})
same => n,Set(channel2=${$[calledsubscriberheld\${desiredpeer}holder]})
same => n,Set(channel2=${$[calledsubscriberheld"${desiredpeer}"holder]})
same => n,Set(channel2=${$["calledsubscriberheld${desiredpeer}holder"]})
same => n,Set(channel2=${$["calledsubscriberheld""${desiredpeer}""holder""]})

I’m not sure I understand what you’re trying to do, but it sounds like this:

        same = n,                       set(desiredpeer=SIP/ATAxLB2)
        same = n,                       set(calledsubscriberSIP/ATAxLB2holder=me)
        same = n,                       verbose(${calledsubscriberSIP/ATAxLB2holder})
        same = n,                       verbose(${calledsubscriber${desiredpeer}holder})
1 Like

That’s what I would have thought intuitively, too, but that hasn’t worked for me in the past. I asked a colleague how he did it and he suggested the format {[something${var}]} which would substitute itself in, and that has worked just fine until now. He has since passed away so I can’t pick his brains on this.
Does this work on your Asterisk system?

Maybe you could try it and post your results, remembering to enclose snippets in preformatted text tags.

Well, now I feel foolish! Apparently it works just fine in Asterisk 18! I recently upgraded and assumed that variables worked the same way they had in previous versions of Asterisk, but apparently they are much improved now (I tried this multiple times in Asterisk 13 and it did not work). I don’t think I would’ve thought to try that again, thanks for the tip!

‘Nesting’ a variable name within a variable name has worked at least as far back as 1.2.

That’s what we’re here for :slight_smile:

'Nesting’ a variable name within a variable name has worked at least as far back as 1.2.

Interesting - I tried to do just this in Asterisk 13, and I couldn’t get it to work, and then I started doing it this way with the $[] as an intermediary to resolve the inner variables into a variable name and then resolve that. In any case, if I can do it directly, I’ve been making things unnecessarily hard for myself for a long time!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.