« Shell Scripting - Trick2 (2 special shell variables) | Main

Shell Scripting - List all the variables that starts with a particular pattern

Ofcourse `env | grep "pattern"` would work if the variables are exported. But you will have
to run 2 commands in pipe and export the variable. Simpler and smarter way to do it? ! and *
for the rescue.

$>var1="asterix"
$>var2="obelix"
$>varIII="getafix"
$>varIV="julius"
$>varFiVe="caeser"
$>echo ${!var*}
var1 var2 varIII varIV varFiVe

Now time for some more magic. You can display the value of all these variables
using this prop
$>for eachVar in ${!var*}; do
echo ${!eachVar}
done

TrackBack

TrackBack URL for this entry:
http://developer.spikesource.com/blogadmin/mt-tb.fcgi/86

Post a comment

About

This page contains a single entry from the blog posted on June 25, 2008 1:20 PM.

The previous post in this blog was Shell Scripting - Trick2 (2 special shell variables).

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type Enterprise
A component of SuiteTwo