From 368657dbb0796eaffe266c46386461c79d2b8c04 Mon Sep 17 00:00:00 2001 From: Brenden Smith Date: Mon, 3 Jun 2024 10:55:19 -0500 Subject: [PATCH] add `getopt` normalization for shell options Prior to this change, the script did not account for options in the form of "-n1" or "-Hserver.com". Normalizing the options with `getopt` allows for the standard POSIX option format to be honored. --- betterspeedtest.sh | 9 +++++++++ 1 file changed, 9 insertions(+) mode change 100644 => 100755 betterspeedtest.sh diff --git a/betterspeedtest.sh b/betterspeedtest.sh old mode 100644 new mode 100755 index 9518a57..99111eb --- a/betterspeedtest.sh +++ b/betterspeedtest.sh @@ -170,7 +170,16 @@ PINGHOST="gstatic.com" MAXSESSIONS="5" TESTPROTO="-4" +# normalize the options # read the options +set -- $(getopt -s sh -u -n 'betterspeedtest.sh' -l 'host:' -l 'time:' -l 'ping:' -l 'number:' '46H:t:p:n:' "${@}") + +# exit if `getopt` fails and pass through exit code +EXIT=$? +if [ $EXIT != 0 ] +then + exit $EXIT +fi # extract options and their arguments into variables. while [ $# -gt 0 ]; do