#!/bin/sh # Author: Ed Levinson # 411 Retrieve information stored in alias files # Storage format (note: ";" is a comment for alias files) # aka1: akaN # aka2: akaN # akaN: Also Known As # ; info1 # ; info2 # ; infoN # Usage: 411 name ... # Bugs: name of alias file should come from .mh_profile # entries for AliasFile and ali (if present). # Limitation: Doesn't do anything for aliases that resolve to # multiple addresses if [ $# -eq 0 ]; then # ask for something! echo Usage: 411 name ... 1>&2 exit 1 fi # generate list of included files f="$HOME/Mail/aliases" # primary alias file while [ "$f" ] # f has files to be searched do # g has files already searched g="$g $f" # accumulate list of files searched # scan files for ones they include, store result in f # includes have the form '<' filename f=`sed ' /^[ ]*&2 shift # move on to the next arg continue # without looking for info fi # retrieve the info and display it sed -n "/$n/"',/^[^;]/{ /^;/!d s/;//p }' $g # remove non-info lines and ";"s shift # next argument done # Commentary # Sed script for include files # delete everything that doesn't include a file # (begins with '<'). # remove beginning '<' and beginning white space # prefix relative path names with their directory # Test for multiple addresses # awk scans result string, n, for a comma which implies # there are several addresses. Before turning the # string over to awk sed eliminates any quoted strings # which can contain anything. If there is a comma awk # returns a failure result code # Sed script for results # select the set of lines starting at match with # resolved email address through first line that # doesn't start with a ';' (slightly more than needed) # remove lines that don't start with ';', the non-info ones # remove ';' and print resulting info