Shell METACHAR's in parameters

David Magnay david at marvin.jpl.oz
Tue Jan 22 11:44:03 AEST 1991


Can anyone supply a "rule" of how to consistently handle shell parameters inside
a script, when the parameter MAY contain shell metacharacters or a regular
expression. The danger is that the shell is will process the characters, rather
than pass them literally.

We also should be able to pass regular expressions down into a script from
within a script, indefinitely. Again, without knowing whether the param has
metachar's or not.

This first showed up in a script to "tidy up" the "find" utility with a
friendlier interface. I found that the script would intermittently fail
silently. If I pass a parameter "file*" as a parameter, it passes literally
if it matches NO files in the current directory, but is expanded if any
matching files exist. ( try "echo kkxx*" ).  This is fixed by the user quoting
the command line when invoking the script. But I still found funnies
occasionally, presuamble because of unwise usage of parameters inside the
script.

What I cant see is the RULE of guidance, so I dont repeat the problem.



More information about the Comp.unix.shell mailing list