 Hello!

As with many here, I am just learning how to use Asterisk without a web interface to do all of the dirty work, and I read about a few built-in variables that can be used in the dialplan, namely “\${EXTEN}”. I know this variable represents the extension that a user dialed, but I have seen this as well: “\${EXTEN:1}”. What is that “:1” at the end of the variable name? I saw this being used when calling the Voicemail() function in the dialplan, but had not idea why you have to have the “:1” at the end of the variable name. Hopefully someone can explain it to me! Thanks!

The \${EXTEN} variable properly has the syntax \${EXTEN:x:y}, where x is the starting position and y is the number of digits to return. Given the following dial string:

94169671111

we can extract the following digit strings using the \${EXTEN:x:y} construct:

``````\${EXTEN:1:3} would contain 416

\${EXTEN:4:7} would contain 9671111

\${EXTEN:-4:4} would start four digits from the end and return four digits, giving us 1111

\${EXTEN:2:-4} would start two digits in and exclude the last four digits, giving us 16967

\${EXTEN:-6:-4} would start six digits from the end and exclude the last four digits, giving us 67

\${EXTEN:1} would give us everything after the first digit, or 4169671111 (if the number of digits to return is left blank, it will return the entire remaining string)
``````

This is a very powerful construct, but most of these variations are not very common in normal use. For the most part, you will be using \${EXTEN} (or perhaps \${EXTEN:1} if you need to strip off an external access code)

Using the \${EXTEN} channel variable

Ah, I see. Thanks for that very helpful post! The substring notation applies to all variables and functions. At least for the simple cases, its use for extensions is reasonably well explained in extensions.conf.sample. More generally, this is explained in Asterisk the Definitive Guide asteriskdocs.org/en/3rd_Edit … SECT-3.6.3 (they incorrectly imply this only works for \${EXTEN}. In earlier versions of Asterisk, the full details where in doc/tex/channelvariables.tex. I presume that is now in the wiki.

\${EXTEN} is not necessarily the number dialed. It is the number that matched the extensions.conf pattern. It can change, temporarily, for macros and subroutines, and permanently, for Goto.

Although accessed with the variables syntax, EXTEN is really a really a function that reads a field in the channel data structure.