Hi,

I am writing a shell script, and need help with a small piece of code.
It is as below:

CUST_1=filename
b=1
c=$CUST_$b
echo $c

I want the output from this as filename, whereas I get it as 1.
Please guide as if where am I going wrong in here.

Recommended Answers

All 2 Replies

Weird, but it can be done.

CUST_1=filename
b=1
eval c=\$CUST_$b
echo $c

There may be easier ways to do what you mean, like using an array. But this works, and gets points for being 'clever'.

Yeah.. that worked... Thanks... :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.