#! /bin/bash # Last edited on 2005-08-20 17:30:21 by stolfi cmd=${0##*/} usage="${cmd} [-timeout NSECS] FILE" # Displays the PS/EPS file, waits for the viewer to be killed. # If "-timeout {NSECS}" is specified with a positive number of seconds, # will kill the viewer automatically after {NSECS} seconds. function error() { echo "${cmd}: $1" >&2; echo "usage: ${usage}" >&2; exit 1; } timeout=0 while [ $# -gt 0 ]; do case "$1" in -timeout ) timeout="$2"; shift; shift ;; -* ) error "unrecognized option $1"; exit 1 ;; * ) break;; esac; done if [ $# -ne 1 ]; then error "wrong number of parameters"; fi viewer=ghostview psfile="$1"; shift; if [ ${timeout} -gt 0 ]; then this=$$ ( ${viewer} ${psfile}; kill -s SIGTERM ${this}; ) & vpid=$! sleep ${timeout} && kill -s SIGTERM ${vpid} else ${viewer} ${psfile} fi