[Slackbuilds-users] RFC: Proposed mandb additions to doinst/douninst template

Nick Smallbone nick at smallbone.se
Wed Sep 11 06:31:55 UTC 2024


On Wed, 11 Sep 2024, at 8:15 AM, B. Watson wrote:
> Someone on IRC pointed out that rewriting it to use awk would be less
> ugly. I tend to reach for sed first due to familiarity, but I think in
> this case you and him are right.
>
> Something like this, maybe?
>
> find usr/man -type f -a -name '*.gz' | \
>    awk '{ print "chroot . /usr/bin/mandb -f \"/"$1"\" &>/dev/null" }' \
>    >> install/doinst.sh
>
> It would be less ugly if we could assume man pages never have spaces
> or shell metacharacters in them... I don't think the man command can
> handle spaces in the man page filenames, and it would be bizarre to
> have $ or * or such in the filename... But better to leave the quotes
> there I suppose.

I just learned that find has a -printf flag which can be used to format the output, avoiding the need for sed/awk altogether:

find usr/man -type f -a -name '*.gz' \
    -printf "chroot . /usr/bin/mandb -f '/%p' &> /dev/null\n" \
    >> install/doinst.sh

There's also a %P format specifier which prints the filename relative to the search root (e.g. man1/whatever.1.gz), hence the following variant which even works if run before the 'cd $PKG' command (but it still needs to come after 'mkdir $PKG/install' so perhaps not a useful improvement):

find $PKG/usr/man -type f -a -name '*.gz' \
    -printf "chroot . /usr/bin/mandb -f /usr/man/%P &> /dev/null\n" \
    >> $PKG/install/doinst.sh

Nick


More information about the SlackBuilds-users mailing list