?
Solved

variable in SHELL on Linux

Posted on 2013-06-04
3
Medium Priority
?
232 Views
Last Modified: 2013-06-04
Have a question on "a variable within a variable:

v1=test1
status_$v1=1
echo "status_$v1=$status_$v1"

Expecting
status_test1=1

but it isn't. How to get it? Thanks.
0
Comment
Question by:jl66
3 Comments
 
LVL 26

Assisted Solution

by:pony10us
pony10us earned 160 total points
ID: 39219387
I don't have a box to test on right now.

What are you getting?

From the way I read it I think you are probably getting:

status_$v1=$status=$v1

Try this:

v1=test1
status_v1=1
echo "status_"$v1"="$status_v1
0
 
LVL 85

Accepted Solution

by:
ozo earned 1840 total points
ID: 39219399
which shell are you using?
You might be able to do something like

v1=test1
eval status_$v1=1
eval echo "status_$v1=\$status_$v1"

Or, if you tell us why you want to do this, we may be able to suggest other means to accomplish that purpose.
0
 

Author Closing Comment

by:jl66
ID: 39219761
Thanks a lot.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question