diff options
author | June McEnroe <june@causal.agency> | 2020-03-03 01:57:23 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-03-03 02:01:41 -0500 |
commit | 190b362eced4ab939e4d74a99e8fe9771ee81014 (patch) | |
tree | 4c1f5010033ee920b76065c52b90371b6b410ddf | |
parent | Style %T outside of Rs in italic (diff) | |
download | src-190b362eced4ab939e4d74a99e8fe9771ee81014.tar.gz src-190b362eced4ab939e4d74a99e8fe9771ee81014.zip |
Use getopts in shell scripts
WTF why did no one tell me about this?
Diffstat (limited to '')
-rw-r--r-- | bin/up.sh | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/bin/up.sh b/bin/up.sh index 0ff9e69b..8b70de70 100644 --- a/bin/up.sh +++ b/bin/up.sh @@ -58,17 +58,16 @@ uploadTerminal() { upload "${temp}/term.html" } -args=$(setopt 'chst' "$@") -eval set -- "$args" -for opt; do +while getopts 'chst' opt; do case "$opt" in - (-c) shift; fn=uploadCommand;; - (-h) shift; fn=uploadHi;; - (-s) shift; fn=uploadScreen;; - (-t) shift; fn=uploadTerminal;; - (--) shift; break;; + (c) fn=uploadCommand;; + (h) fn=uploadHi;; + (s) fn=uploadScreen;; + (t) fn=uploadTerminal;; + (?) exit 1;; esac done +shift $(($OPTIND - 1)) [ $# -eq 0 ] && : ${fn:=uploadText} : ${fn:=upload} |