0

This is my script:

#!/bin/bash

AREA="DEV"
DEV_AREA_USER="DevAdmin"
TEST_AREA_USER="TestAdmin"

TEST=${$AREA_AREA_USER}
echo ${TEST}

Result: Bad substitution error. Expected result: DevAdmin
How to fix this? I do not want to create a new variable because there are 75 such variables and 75 files to edit. The lesser the better...

user1164061
  • 4,222
  • 13
  • 48
  • 74
  • @Barmar - The question you are referring to has the value of a variable whose name is stored in another variable. So its easy to echo it. Mine is a combination of one variable plus few more text added to it to make it another another variable AND i do not want to use an extra variable. Can you please unmark it as a duplicate please? – user1164061 Sep 10 '19 at 00:35
  • 2
    You have to use an extra variable, then use the indirect variable as shown. `varname=${AREA}_USER; echo ${!varname}` – Barmar Sep 10 '19 at 01:37
  • There's no single-line way, other than using `eval`. – Barmar Sep 10 '19 at 01:37
  • @barmar - ok. Thank you! Can you take away the duplicate tag for this question so that others can attempt to answer this ? Maybe someone knows a way and can help me with an answer... – user1164061 Sep 10 '19 at 02:00
  • There are plenty more duplicates, some with the same constraint. They all have the same answer. This is a well-known/common FAQ. – Charles Duffy Sep 10 '19 at 02:32
  • @CharlesDuffy - Ok.. please provide links so that I can learn from it; – user1164061 Sep 10 '19 at 02:33
  • 1
    I added a few additional duplicates (to the header at the top of the question); also see [BashFAQ #6](http://mywiki.wooledge.org/BashFAQ/006). – Charles Duffy Sep 10 '19 at 02:34

0 Answers0