Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

in bash can I wildcard varables

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
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
Course of the Month10 days, 11 hours left to enroll

885 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