Solved

variable in SHELL on Linux

Posted on 2013-06-04
3
225 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 40 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 84

Accepted Solution

by:
ozo earned 460 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

772 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