Variable types

Four type of variables are available in Asterisk:

  • Global variables – can be set either in the [globals] category of the extensions.conf file or by using the SetGlobalVar command. Once defined, these variables are visible to all channels at all times. Here is an example:
[globals]
HELLEN=SIP/300

The first line in the code above begins the global variables section. The second line creates a global variable named HELLEN with a value of SIP/300. We can use that variable later in the dialplan (e.g. the exten => 300,1,Dial(${HELLEN})) line will be interpreted by Asterisk as exten => 300,1,Dial(SIP/300))

  • Shared variables – variables that can be shared between channels with the help of the SHARED function.
  • Channel variables – can be set using the Set command (SetVar in older version of Asterisk). Channel variables are associated only with a particular call and are automatically trashed when the channel is hungup. The variable JOHN that we’ve defined in the previous section is an example of a channel variable.
  • Environment variables – the environment variables of the underlying Linux system. They are referenced using the ENV() function.
Geek University 2022