?
Solved

variable in SHELL on Linux

Posted on 2013-06-04
3
Medium Priority
?
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 84

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

770 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