Question: CODE with details
=================

```
#!/usr/bin/bash -xv

```

FUNCTION\_DYNAMIC
=================

```
eval "function APP_$i_$j
{
    `enter code here`
}"

```

DEFINING\_FUNC\_TO\_CALCULATE\_VALUE
====================================

```
APP_VAR_MKT()
{
    for i in `cat ${SERVER}`
    do
        for j in `cat ${ZONE}`
        do
            shopt -s expand_aliases
            alias name="APP_${i}_${j}"
            declare -fp "APP_${i}_${j}"
        done
    done
}

```

MAIN
====

```
SERVER_NAME=/path/servers_file
ZONE=/path/zones_file

```

DECLARING FUNCTION with variable in it
======================================

```
APP_VAR_MKT

```

Answer: 
You don't; you pass that information as arguments:

```
app () {
    server_name=$1
    zone=$2
    # ...
}

app "$SERVER_NAME" "$ZONE"

```
As others have said, it is not a good idea to generate function (or variable) names dynamically, instead you can use an associative array in a structure sometimes called a *despatch table*.

The idea is that the keys of the associative array (sometimes called a 'hash', 'hash table', or dictionary) hold the names of functions. When you need a particular function you just call it. Here is a simple example:

```
# Statically declare each function

func1() {
    echo "This is func1"
}

func2() {
    echo "This is func2"
}

# Declare the array as associative
declare -A lookup

# Setup the association of dynamic name with function
lookup[APP_fred_CBD]='func1'
lookup[APP_jim_ABCD]='func2'

SERVER_NAME='fred'
ZONE='CBD'
${lookup[APP_${SERVER_NAME}_${ZONE}]}

SERVER_NAME='jim'
ZONE='ABCD'
${lookup[APP_${SERVER_NAME}_${ZONE}]}

```

Gives:

```
This is func1
This is func2

```

If you application does not require unique functions, you can use the same function for more than one key, and pass parameters.