Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

in bash can I wildcard varables

Posted on 2014-12-12
3
Medium Priority
?
154 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 1000 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 1000 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
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 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.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

722 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