--- bzip2/bzdiff +++ bzip2/bzdiff @@ -12,7 +12,10 @@ # necessary) and fed to cmp or diff. The exit status from cmp # or diff is preserved. -PATH="/usr/bin:/bin:$PATH"; export PATH +[ -z "$PATH" ] && + PATH="/bin:/usr/bin" || + PATH="/bin:/usr/bin:$PATH" +export PATH prog=`echo $0 | sed 's|.*/||'` case "$prog" in *cmp) comp=${CMP-cmp} ;; @@ -37,10 +40,6 @@ if test -z "$FILES"; then echo "Usage: $prog [${comp}_options] file [file]" exit 1 fi -tmp=`mktemp ${TMPDIR:-/tmp}/bzdiff.XXXXXXXXXX` || { - echo 'cannot create a temporary file' >&2 - exit 1 -} set $FILES if test $# -eq 1; then FILE=`echo "$1" | sed 's/.bz2$//'` @@ -52,11 +51,16 @@ elif test $# -eq 2; then *.bz2) case "$2" in *.bz2) + tmp="`mktemp -t bzdiff.XXXXXXXXXX`" || { + echo 'cannot create a temporary file' >&2 + exit 1 + } + trap 'rm -f -- "$tmp"' EXIT + trap 'trap - EXIT; rm -f -- "$tmp"; exit 1' HUP INT QUIT PIPE TERM F=`echo "$2" | sed 's|.*/||;s|.bz2$||'` - bzip2 -cdfq "$2" > $tmp - bzip2 -cdfq "$1" | $comp $OPTIONS - $tmp - STAT="$?" - /bin/rm -f $tmp;; + bzip2 -cdfq "$2" > "$tmp" + bzip2 -cdfq "$1" | $comp $OPTIONS - "$tmp" + STAT="$?";; *) bzip2 -cdfq "$1" | $comp $OPTIONS - "$2" STAT="$?";;