Code Snippets

#!/usr/bin/env bash
set -euo pipefail

verbose=0
count=1
name=""

while getopts ":vc:n:" opt; do
    case $opt in
        v) verbose=1 ;;
        c) count="$OPTARG" ;;
        n) name="$OPTARG" ;;
        :) echo "missing arg for -$OPTARG" >&2; exit 1 ;;
        \?) echo "unknown -$OPTARG" >&2; exit 1 ;;
    esac
done

printf 'name=%s count=%d verbose=%d\n' "$name" "$count" "$verbose"