#!/bin/sh COUNT=1 ENAME=${0##*/} : ${XTERM:=xterm} _error() { printf "%s: %s\n" "$ENAME" "$*" 1>&2 } _isint() { test "$1" -gt 0 2>/dev/null 1>&2 } _runterm() { if [ -z "$1" ]; then "$XTERM" $XTERM_OPTS & else "$XTERM" $XTERM_OPTS -e "$@" & fi } _usage() { printf \ "usage: %s %s [COMMAND [ARGUMENTS ...]]\n" \ "$ENAME" \ "[-c COUNT] [-o XTERM_OPTIONS] [-x XTERM]" 1>&2 [ "$#" -gt 0 ] && for MSG; do _error "$MSG" done exit 1 } while getopts "c:o:x:" OPTION; do case "$OPTION" in c) if _isint "$OPTARG"; then COUNT="$OPTARG" else _usage "invalid COUNT: $OPTARG" fi ;; o) XTERM_OPTS="$OPTARG" ;; x) if type "$OPTARG" 2>/dev/null 1>&2; then XTERM="$OPTARG" else _usage "could not locate terminal emulator: $OPTARG" fi ;; \?) _usage ;; esac done shift "$(( $OPTIND - 1 ))" if [ ! -z "$1" ]; then type "$1" 2>/dev/null 1>&2 || _usage "could not locate command: $1" fi for INDEX in $(seq "$COUNT"); do _runterm "$@" done