Solved

variable in SHELL on Linux

Posted on 2013-06-04
3
219 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks a lot.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now