Issue in shell script variables

Hi,

I have a file at $HOME/t.txt , below is file content

cat $HOME/t.txt
CUSTOMER_${REGION}.out

Am using this file content in one script $HOME/samp.sh , below is the script

#!/bin/bash
REGION=USA
x=`cat ${HOME}/t.txt`

echo $x

Am getting following output.. CUSTOMER_${REGION}.out

Expected output is CUSTOMER_USA.out , can you please help me to get this.

Thanks

Indirection can't be done like that in shell. What do you need that construct for?

Use arrays, or, in bash, indirected variables (like ${!REGION}) might help. The use of eval for the assignment can be dangerous and is therefore deprecated.

Hi,
Thanks for the reply.

REGION value vary from run to run, so we would like to pass it as mentioned.

Looks like arrays would not help here, REGION will get run time same needs to replace in file name.

Thanks

OSX 10.7.5, default bash terminal...

Just an idea, and not sure if this might work for you, first $HOME/t.txt ...
Note the variable "x" is now in the "t.txt" file...

cat $HOME/t.txt
x=CUSTOMER_${REGION}.out

And the script:-

#!/bin/bash
REGION=USA
source "$HOME/t.txt"
echo "$x"

Results:-

Last login: Mon Feb  1 20:14:29 on ttys000
AMIGA:barrywalker~> ./sub.sh
cat $HOME/t.txt
x=CUSTOMER_${REGION}.out
CUSTOMER_USA.out
AMIGA:barrywalker~> _