#!/bin/dash TO_UPPER="" TO_LOWER="" PREFIX= SUFFIX= FILTER_VOWELS="" ARGC=0 usage() { cat << EOF usage: $0 [-luvh] [-p prefix] [-s suffix] [inputs...] options: -l convert inputs to lowercase -u convert inputs to uppercase -v remove vowels from inputs -h show help -p prefix add \`prefix\` to each line before inputs -s suffix add \`suffix\` to each line after inputs notes: if -l and -u are specified at the same time, the lowercase option will have precedence EOF exit $1 } while getopts dulhp:s:v OPT; do [ $OPTIND -gt $ARGC ] && ARGC=$OPTIND case $OPT in u) TO_UPPER="y" ;; l) TO_LOWER="y" ;; h) usage 0 ;; p) PREFIX=$OPTARG ;; s) SUFFIX=$OPTARG ;; v) FILTER_VOWELS="y" ;; \?|*) usage 1 ;; esac done [ $(( $# - $ARGC )) -lt 0 ] && echo "please provide some input" && usage 1 shift $(( ARGC - 1 )) while [ -n "$1" ]; do OUT="$1" [ -n "$TO_UPPER" ] && OUT="`echo "$OUT" | sed 's/./\U\0/g'`" [ -n "$TO_LOWER" ] && OUT="`echo "$OUT" | sed 's/./\L\0/g'`" [ -n "$FILTER_VOWELS" ] && OUT="`echo "$OUT" | sed 's/[aeuio]//g'`" echo "$PREFIX$OUT$SUFFIX" shift done