Solved

in bash can I wildcard varables

Posted on 2014-12-12
3
147 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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.

772 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