From 513579b749e260d3451bfae57bcb6f17526b4e82 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Tue, 3 Mar 2020 02:08:44 -0500 Subject: Use getopts --- git-fetch-email.sh | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/git-fetch-email.sh b/git-fetch-email.sh index 704651b..80b3bb7 100644 --- a/git-fetch-email.sh +++ b/git-fetch-email.sh @@ -26,22 +26,19 @@ from=$(git config fetchemail.from) to=$(git config fetchemail.to) cc=$(git config fetchemail.cc) -args=$(getopt 'C:F:S:T:h:m:p:' $*) -[ $? -ne 0 ] && exit 1 -set -- $args -for opt; do - shift; +while getopts 'C:F:S:T:h:m:p:' opt; do case "$opt" in - (-C) cc=$1; shift;; - (-F) from=$1; shift;; - (-S) subject=$1; shift;; - (-T) to=$1; shift;; - (-h) host=$1; shift;; - (-m) mailbox=$1; shift;; - (-p) port=$1; shift;; - (--) break;; + (C) cc=$OPTARG;; + (F) from=$OPTARG;; + (S) subject=$OPTARG;; + (T) to=$OPTARG;; + (h) host=$OPTARG;; + (m) mailbox=$OPTARG;; + (p) port=$OPTARG;; + (?) exit 1;; esac done +shift $(($OPTIND - 1)) [ $# -ne 0 ] && user=$1 if [ -z "${user:-}" ]; then echo "$0: username required" -- cgit 1.4.1