Web page hosting and cheap domain registration & search engine ranking services
  

 

The mhprofile Shell Script

[return-to Explanation of mhprofile] [table of contents] [index]

#! /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
 

 

 

 
 

Disclaimers: This document is provided as free service for the benefits of Active-Venture.com's web hosting customers only.

 
Quotes: