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:


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.


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.


Note the single quotes, and the removed double quotes!


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
iterationlog="`echo iterationlog`*.runlog"
Sorry, typo:

iterationlog="`echo $iterationlog`*.runlog"
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.


echo "$iterationlog"  to check!

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


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.

dhite99Author Commented:
Yep, that's it, thanks!!!!
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.