sh script question
Jonathan I. Kamens
jik at athena.mit.edu
Sat Apr 13 06:11:58 AEST 1991
In article <16387 at fibercom.COM>, rrg at fibercom.COM (Rhonda Gaines) writes:
|> I am trying to edit the following script to check if a man page has been
|> compressed and if so to pipe it through zcat first and then eroff it.
|> The problem is that sh is not recognizing the *.Z as a wildcard. Any ideas?
|> I'm pretty new at this so any help will be appreciated.
I see several problems with your script.
The first is here:
|> if test "$FILES" = "" ; then
This isn't really a problem, more of a stylistic thing, but I would use the
"-z" option to test to see if the string is zero-length, i.e.:
if test -z "$FILES" ; then
Same thing here:
|> if test "$2" = "" ; then
I would use:
if test -z "$2" ; then
Here's the first real problem:
|> if test "$FILES" = "*.Z" ; then
First of all, the "test" command doesn't support file wildcard matching, which
is what you're trying to get it to do. You probably want to use something
like this:
if test `expr "$FILES" : ".*\.Z"` -gt 0 ; then
However, this isn't really enough either. Remember, your "find" command above
may find *one or more files* that match the name specified to the shell
script. This means that the FILES variable may contain one or more files, but
your entire script (including this check, and the zcat and eroff commands
later in the script) are treating the variable as if it only contains one
file. You probably won't have any trouble if all of the files in FILES are
compressed or if they all aren't compressed, but if some of them are
compressed and some aren't then things will go badly.
What you want to do is replace this line in your script:
|> FILES=`find /usr/man/man*$2* -name "$1.*" -print`
With this:
for FILES in `find /usr/man/man*$2* -name "$1.*" -print` ; do
and then add
done
at the bottom of the script. This will deal with each file, checking whether
or not it is compressed, individually.
I hope all this helps.
--
Jonathan Kamens USnail:
MIT Project Athena 11 Ashford Terrace
jik at Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8085 Home: 617-782-0710
More information about the Comp.unix.questions
mailing list