Solved

in bash can I wildcard varables

Posted on 2014-12-12
3
153 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
[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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

617 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