Korn Shell - How to Use "*" In a Variable


Hi - I have what I think should be a simple question - somehow the answer is eluding me.

I have the following code:

 iterationlog=`echo $this_script $sn_length | awk '{ $1 = substr($1,1,$2); print $1}'`

After executing the above, the variable "iterationlog" contains the word rmanmon. This is expected.

Next I have the following code:

iterationlog="${iterationlog}*.runlog"

After the execution of that statement, the variable "iterationlog" contains a directory listing of the current directory for everything ending in *.runlog.

What I need is for the variable iterationlog to contain the the string "rmanmon*.runlog" (no quotes). After that I will execute an ls -1 $iterationlog in the script for further processing.

Any help on how to overcome the asterisk showing the directory contents would be greatly appreciated.

Thanks!

dhite99Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
woolmilkporcCommented:
iterationlog=${iterationlog}'*'.runlog

Note the single quotes, and the removed double quotes!

wmp
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
medveddCommented:
iterationlog="`echo iterationlog`*.runlog"
0
 
medveddCommented:
Sorry, typo:

iterationlog="`echo $iterationlog`*.runlog"
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
woolmilkporcCommented:
Use

echo "$iterationlog"  to check!

echo $iterationlog without double quotes will expand the asterisk "*"!

0
 
woolmilkporcCommented:
Explanation:

Even if the variable's name correctly contains the asterisk,

echo $variable

will make the shell expand the name to all matching filenames in the current directory.

In ksh you can use

set -o noglob

to turn off this so-called "filename globbing" ,

or (see above) just put the variable's name between double quotes.

wmp
0
 
dhite99Author Commented:
Yep, that's it, thanks!!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.