# Asterisk Project : Channel Variables Basics

Added by malcolmd , edited by mmichelson on Mar 14, 2011

Channel variables are variables that are set for the current channel (one leg of a bridged phone call). They exist for the lifetime of the channel, and then go away when that channel is hung up. Channel variables on one particular channel are completely independent of channel variables on any other channels; in other words, two channels could each have variables called COUNT with different values.

To assign a value to a channel variable, we use the Set() application. Here's an example of setting a variable called COUNT to a value of 3.

    exten=>6123,1,Set(COUNT=3)

To retrieve the value of a variable, we use a special syntax. We put a dollar sign and curly braces around the variable name, like ${COUNT}

When Asterisk sees the dollar sign and curly braces around a variable name, it substitutes in the value of the variable. Let's look at an example with the SayNumber() application.

    exten=>6123,1,Set(COUNT=3)
    exten=>6123,n,SayNumber(${COUNT})

In the second line of this example, Asterisk replaces the ${COUNT} text with the value of the COUNT variable, so that it ends up calling SayNumber(3).