#!/bin/sh set -u #abort when undefined vars are used # Frobnicator # # Copyright (C) 2016 Assaf Gordon # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . die() { BASE=$(basename "$0") echo "$BASE: error: $*" >&2 exit 1 } show_help_and_exit() { BASE=$(basename "$0") echo \ "Frobnicator - fronbnicates files Usage: $BASE [OPTIONS] FILE Options: -h = This help screen. -v = Be verbose. -P POOPOO = A random option " exit } ## ## Script start, parse command-line parameteres ## show_help= verbose= poopoo= # Parse parameters while getopts hvp: param do case $param in h) show_help=1;; v) verbose=1;; p) poopoo="$OPTARG";; ?) die "unknown/invalid command line option";; esac done shift $(($OPTIND - 1)) test -n "$show_help" && show_help_and_exit # Ensure is one non-option parameters (the input file) test $# -gt 1 && die "too many parameters ($*). See -h for help." test $# -lt 1 && die "missing input file. See -h for help." # first parameter - filename infile="$1" test -z "$infile" && die "missing input file. See -h for help." test -e "$infile" \ || die "input file '$infile' not found" test "$poopoo" \ && msg="poopoo = '$poopoo'" \ || msg="no poopoo" test "$verbose" && echo "Processing file '$infile' ($msg)"