Solved

variable in SHELL on Linux

Posted on 2013-06-04
3
229 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 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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 …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

690 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