[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Simple scripting: Prevent an "*" in a variable from resolving during runtime

Posted on 2005-04-25
4
Medium Priority
?
206 Views
Last Modified: 2013-12-27
Hopefully this is a simple question.  It was triggered while I was trying to help someone ELSE in EE with scripting.

Is there a way to stop a variable with an “*” in it from resolving the “*” at runtime?

I.E.
In the script called test2...
************
#!/bin/ksh
for var in $*
do
 echo $var
done
**********

...I get the following results if I run ...
ksh # ./test2 a b "test" d
a
b
test
d

...which is what I want.  HOWEVER, if I run the script with the following parameters ...

ksh # ./test2 a b "*test*" d
a
b
test
test1,ksh
test2
test2.ksh
test3
d

...I get a listing of all the “test” files in the dir...instead of it listing “*test*” WITH the asterisks, like follows ...
a
b
*test*
d

How do I get it to echo (or grep or whatever) the “*test*” WITH the asterisks, instead of functionally resolving them?

Many Thanks!
M
0
Comment
Question by:Mike R.
  • 3
4 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 2000 total points
ID: 13863264
You need to disable shell globbing.

This depends on what shell you are running.  For ksh/bash, you do:

set -o noglob

at the command prompt.

0
 
LVL 3

Author Comment

by:Mike R.
ID: 13863286
can that be done within the script (so it affects on the child shell being generated by the script?)
0
 
LVL 3

Author Comment

by:Mike R.
ID: 13863292
Nevermind...a quick shell test answered the question to "yes".

Thanks!  I new it would be something easy :-)!

M
0
 
LVL 3

Author Comment

by:Mike R.
ID: 13863296
By the way...I think it was the "multigrep" question that you answered, that inspired the question in the first place :-D

Thanks again!
M
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.:
Suggested Courses
Course of the Month18 days, 5 hours left to enroll

829 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