Skip to Content.
Sympa Menu

baslinux - Re: [BL] Fixed My Man Script (take two)

baslinux AT lists.ibiblio.org

Subject: Baslinux mailing list

List archive

Chronological Thread  
  • From: Lee Forrest <lforrestster AT gmail.com>
  • To: baslinux AT lists.ibiblio.org
  • Subject: Re: [BL] Fixed My Man Script (take two)
  • Date: Sun, 31 Dec 2006 13:29:26 +0000

Hello Karolis,

On Sun, Dec 31, 2006 at 01:11:37PM +0200, Karolis Lyvens wrote:
> On Sat, Dec 30, 2006 at 08:32:17PM +0000, Lee Forrest wrote:
> > Let's try again, with another fix and an improvement:
> >
> > (I neglected to include full paths to all the files referred
> > to.)
> >
> > On Sat, Dec 30, 2006 at 07:35:52PM +0000, Lee Forrest wrote:
> >
> > ----------
> > #!/bin/sh
> >
> > #for plain text man pages gzipped in /usr/man
> >
> > # put your favorite editor here
> >
> > ed=/usr/bin/nvi
> >
> > # assign first arg to man on the commandline to the variable
> > # 'file'
> # Error checking here would help:
> if test -n $1; then
> # Or, alternately:
> #if [ -n $1 ]; then
> file=$1
> fi

That's what this below does, taking a different approach.

> >
> > # test if there isn't any such manpage, and if that's the
> > # case, say so and exit with an error code (1)
> >
> > if ! test -s /usr/man/${file}.gz
> > then echo "No Such Manpage"
> > exit 1
> > fi
> >
> > # see if /usr/man/${1}.gz is a symlink.
>
> >
> > if test -h /usr/man/${file}.gz
> >
> > # if it is, extract the name of the manpage, minus the ".gz"
> > # and assign it to $file
> >
> > then file=`ls -l /usr/man/${file}.gz | sed -n 's/^\(.*
> > \)\(.*\)\(.gz$\)/\2/p'`
>
> Why the "ls -l"? The regexp doesn't use any information from
> "ls -l" anyway.

Yes it does. I uses the name of the target of the symlink, which
is the last word in the output of ls -l.

That's the whole point. Otherwise, the symlink is dereferenced
and you end up with a copy of the target named ${1}.gz instead
of the symlink. That defeats the purpose of the symlink, which
is to avoid duplicates.

Caught me by surprise, too.

> The same result could be achieved by a much shorter regexp:
>
> ---
> then file=`ls /usr/man/${file}.gz | sed 's/\(.*\)\.gz$/\1/'`
> ---

Nope. Try it.

That works fine when the file isn't a symlink.

>
> Both substitutions with sed leave pathname intact, which would
> expand the later "gunzip /usr/man/${file}.gz" (when $1 == ash) to
> "/usr/man/usr/man/ash.gz". It helps to know some other utilities (that
> are included in busybox):
>
> ---
> then file=`basename /usr/man/${file}.gz .gz`
> ---

That's what I did the first time. Doesn't matter whether
you use basename or sed.

Lee

--
BasicLinux: Small is Beautiful
http://www.basiclinux.com.ru





Archive powered by MHonArc 2.6.24.

Top of Page