[TynesideLUG] shell script: man-section

Ian Bruntlett ian.bruntlett at gmail.com
Tue Aug 10 17:54:01 UTC 2021


Hi,

There is a small bug in my man-section shell script, shared here earlier.
When passed no parameters, the program exited with a code of 0 (signalling
no error). I've changed it to 1 which will indicate to the caller that
something Went Wrong.

The code in question is highlighted in bold...

HTH,


Ian

#!/usr/bin/env bash
# 2021-07-11 Ian Bruntlett
# 2021-07-14 Tidying up heredoc in "Usage" function.
# 2021-08-10 Return an error code when called with no parameters
# Name   : man-section
# Purpose: To dig around the man pages

function Usage
{
cat <<END-OF-USAGE-MESSAGE
Usage: $0 section-number (from 1 to 9, optional)
       1   Executable programs or shell commands
       2   System calls (functions provided by the kernel)
       3   Library calls (functions within program libraries)
       4   Special files (usually found in /dev)
       5   File formats and conventions, e.g. /etc/passwd
       6   Games
       7   Miscellaneous (including macro packages and conventions), e.g.
man(7),
           groff(7)
       8   System administration commands (usually only for root)
       9   Kernel routines [Non standard]
END-OF-USAGE-MESSAGE
}

if [ $# -eq 0 ]; then
    Usage >&2

*    exit 1*fi

while [ "$1" != "" ]; do
  man -k "[a-z]" -s "$1"
  shift
done


-- 
-- ACCU - Professionalism in programming - http://www.accu.org
-- My writing - https://sites.google.com/site/ianbruntlett/
-- Free Software page -
https://sites.google.com/site/ianbruntlett/home/free-software


More information about the Tyneside mailing list