# Variable substitution error

**URL:** <https://community.unix.com/t/variable-substitution-error/178896>\
**Category:** Shell Programming and Scripting\
**Created:** [December 12, 2007, 2:15am UTC](https://community.unix.com/t/variable-substitution-error/178896 "2007-12-12T02:15:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cosec](https://community.unix.com/letter_avatar/cosec/32/5_5575768a8748004e209b776fc1b2916d.png) [@cosec](https://community.unix.com/u/cosec)\
**Post date:** [December 12, 2007, 2:15am UTC](https://community.unix.com/t/variable-substitution-error/178896/1 "2007-12-12T02:15:12Z")

</div>

Hi  
The following command gives me error :The specified substitution is not valid for this command

export DB\_ID=${DB\_${MART}\_USER}

What is the correct syntax for the above ?

---

<div class="post-metadata">

**Author:** ![porter](https://community.unix.com/letter_avatar/porter/32/5_5575768a8748004e209b776fc1b2916d.png) [@porter](https://community.unix.com/u/porter)\
**Post date:** [December 12, 2007, 3:12am UTC](https://community.unix.com/t/variable-substitution-error/178896/2 "2007-12-12T03:12:12Z")

</div>

something like

```nohighlight
DB_ID=`sh -c "echo DB_${MART}_USER"`
DB_ID=`sh -c "echo \$$DB_ID"`
export DB_ID

```

or you could try eval

---

<div class="post-metadata">

**Author:** ![rikxik](https://community.unix.com/user_avatar/community.unix.com/rikxik/32/752_2.png) [@rikxik](https://community.unix.com/u/rikxik)\
**Post date:** [December 12, 2007, 3:18am UTC](https://community.unix.com/t/variable-substitution-error/178896/3 "2007-12-12T03:18:38Z")

</div>

I think you want this:

> [@](#):
>
> $ MART=wall  
> $ DB\_wall\_USER=wallmart  
> $ eval eval export DB\_ID=\${DB\_${MART}\_USER}  
> $ echo $DB\_ID  
> wallmart

HTH.

---

<div class="post-metadata">

**Author:** ![cosec](https://community.unix.com/letter_avatar/cosec/32/5_5575768a8748004e209b776fc1b2916d.png) [@cosec](https://community.unix.com/u/cosec)\
**Post date:** [December 12, 2007, 3:29am UTC](https://community.unix.com/t/variable-substitution-error/178896/4 "2007-12-12T03:29:44Z")

</div>

Hi

Thanks for the suggestion but It doesnt seem to retrieve the value of the variable correctly in 2

(1)  
DB\_ID=`sh -c "echo DB_${MART}_USER"`

Result = DB\_XMM\_USER  
(2)  
DB\_ID=`sh -c "echo \$$DB_ID"`  
Result = 1233DB\_ID

I need to be able to get the value of DB\_XMM\_USER ie ${DB\_XMM\_USER}

---

<div class="post-metadata">

**Author:** ![porter](https://community.unix.com/letter_avatar/porter/32/5_5575768a8748004e209b776fc1b2916d.png) [@porter](https://community.unix.com/u/porter)\
**Post date:** [December 12, 2007, 3:40am UTC](https://community.unix.com/t/variable-substitution-error/178896/5 "2007-12-12T03:40:07Z")

</div>

> [@cosec](#):
>
> DB\_ID=`sh -c "echo \$$DB_ID"`  
> Result = 1233DB\_ID

Seems you did

DB\_ID=`sh -c "echo $$DB_ID"`

where $$ expanded to the current process id.

The slash prefixing the first $ is to have it taken literally.
