#! /bin/sh # Shell script template beginswith() { case "$2" in "$1"*) true;; *) false;; esac; } print_error_and_die() { errmessage="$@" echo -"\e[31m##[error]$errmessage\e[0m" >&2 exit 1 } info() { # print blue msg="$@" echo "\e[34m$msg\e[0m" } yellow() { msg="$@" echo "\e[33m$msg\e[0m" } usage() { info "$0 : example sh script" info "-h : print usage information" } # parameters expecting an argument are followed by : # flags have no : EXAMPLE= OPSTRING=":he:" while getopts "$OPSTRING" opt; do case $opt in h) usage exit 0 ;; e) EXAMPLE="$OPTARG" ;; \?) usage print_error_and_die "Unknown option: -$OPTARG" ;; :) usage print_error_and_die "Option -$OPTARG requires an argument." ;; esac done