The original Shell Script

[return-to Explanation of original] [table of contents] [index]
#!/bin/sh
# $Id: original,v 1.0 1995/04/26 17:29:19 jerry book3 $
#
### original - Replace mhn-edited draft with original containing directives
### Usage:  What now? edit original

t=','   # CHARACTER mhn PREPENDS TO DRAFT FILENAME TO MAKE IT "TEMPORARY"

# $mhdraft HAS DRAFT PATHNAME.  IF NOT SET, PRINT TWO-LINE ERROR AND EXIT:
: ${mhdraft?"aborting: mhdraft not set in environment.
Be sure that you're using this from a 'What now?' prompt."}

# PUT DRAFT DIRECTORY IN $dir, DRAFT FILE IN $file:
eval `echo "$mhdraft" | sed 's@\(.*\)/\(.*\)@dir="\1" file="\2"@'`

cd "$dir" || {
    echo "`basename $0` aborting: can't cd to draft directory '$dir'?" 1>&2
    exit 1
}

case "$file" in
draft|[1-9]*) orig="$t$file.orig" ;;
*)  echo "`basename $0` aborting: invalid draft filename '$file'?" 1>&2
    exit 1
    ;;
esac

if test ! -r "$file" -o ! -r "$orig" -o ! -w "$file"
then
    echo "`basename $0` aborting: can't read draft '$orig' and/or read/write '$file'" 1>&2
    exit 1
fi

/bin/mv "$file" "$t$file.mhn" || {
    echo "`basename $0` aborting: can't rename '$file' to '$t$file.mhn'?" 1>&2
    exit 1
}

/bin/mv "$orig" "$file" || {
    echo "`basename $0` aborting: can't rename '$orig' to '$file'?" 1>&2
    exit 1
}

[Table of Contents] [Index] [Return to Explanation of original]


Last change $Date: 1996/06/06 15:13:50 $

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>

HIVE: All information for read only. Please respect copyright!
Hosted by hive КГБ: Киевская городская библиотека