• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 494
  • Last Modified:

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!

0
dhite99
Asked:
dhite99
  • 3
  • 2
2 Solutions
 
woolmilkporcCommented:
iterationlog=${iterationlog}'*'.runlog

Note the single quotes, and the removed double quotes!

wmp
0
 
medveddCommented:
iterationlog="`echo iterationlog`*.runlog"
0
 
medveddCommented:
Sorry, typo:

iterationlog="`echo $iterationlog`*.runlog"
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now