Solved

in bash can I wildcard varables

Posted on 2014-12-12
3
150 Views
Last Modified: 2014-12-12
If I have these variables
 in bash  

Mywife
MyDog
JoesProblems

I would like to echo $My*


Is there a way to do this ?  I want to simplify reporting

Redhat 567
0
Comment
Question by:TIMFOX123
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 40496630
echo ${!My*}
How does this simplify reporting  Redhat 567 ?

If
MyDog=Redhat
and
Mywife=567
then you might run
for v in ${!My*} ; do echo ${!v} ;  done
But it seem easier to use an array
My=(Redhat 567)
echo ${My[*]}
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 250 total points
ID: 40496797
I think that you want to see the values along with the variable names.

If so, try

set | grep '^My'

But if you want to see just the values, try

set | grep '^My' |cut -f2 -d"="
0
 

Author Comment

by:TIMFOX123
ID: 40496800
I have a script that figures out a lot of stuff on a system and has 30 varables now and going for hundreds

If I use logical names like  network.interface.eth0
                                            network.gateway
                                            filesystem.root
                                            filesystem.user
I could use grouping names for my reporting.  If I am checking systems that are running for a while I would care about file systems. If I just rebooted, I would care about interfaces ( usually bonds )
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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 …
This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

821 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