#! /bin/sh
# $Id: mhprofile,v 1.6 92/07/24 17:36:00 jerry book2 $
### mhprofile - show matching line(s) from MH profile file
### Usage: mhprofile [-b] component-name
##
## USE mhprofile TO READ A LINE FROM THE .mh_profile FILE.
## FOR EXAMPLE, IF YOU WANT TO READ THE "DRAFT-FOLDER" LINE, TYPE:
## $ mhprofile draft-folder
## Draft-Folder: drafts
## THE -b OPTION STRIPS OFF THE COMPONENT NAME. EXAMPLE:
## $ mhprofile -b draft-folder
## drafts
##
## RETURNS 0 IF MATCH FOUND, 1 IF NO MATCHES, 2 ON ERRORS
##
## NOTE TO HACKERS: TABSTOPS ARE SET AT 4 IN THIS CODE
grep=/bin/grep # HAS -i OPTION, HANDLES REGULAR EXPRESSIONS
sed=/bin/sed
profile=${MH-${HOME?}/.mh_profile} # COMPLAIN, EXIT IF $HOME NOT SET
# GET -b OPTION, IF ANY, AND shift IT AWAY:
case "$1" in
-b) stripname=y; shift;;
-*) echo "Usage: `basename $0` [-b] component-name" 1>&2; exit 2 ;;
esac
# ONLY REMAINING ARGUMENT SHOULD BE A COMPONENT NAME:
case $# in
1) ;;
*) echo "`basename $0` quitting: wrong number of args." 1>&2; exit 2 ;;
esac
# IF grep FAILS, RETURN ITS STATUS (1=NO MATCH, 2=ERROR):
lines="`$grep -i \"^${1}:\" $profile`" || exit
# IF -b SET, USE sed TO SEARCH AND STRIP OFF LABEL+WHITESPACE.
# ASSUME NO COLON IN NAME, ":" AND MAYBE WHITESPACE AFTER NAME:
case "$stripname" in
y) echo "$lines" | $sed -n 's/^[^:]*:[ ]*//p' ;;
*) echo "$lines" ;;
esac
exit 0 # A LITTLE PRESUMPTUOUS
[Table of Contents] [Index] [Return to Explanation of mhprofile]
This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright © 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.
Suggestions are welcome: Jerry Peek <jerry@ora.com>