From b7b0d474eb545edf16b35c03a4de05be68b7f815 Mon Sep 17 00:00:00 2001 From: Daniel Abromeit aka Abro Date: Fri, 2 Jul 2021 20:05:41 +0200 Subject: [PATCH] show usage when script is called without arguments Fixes https://github.com/jaygooby/ttfb.sh/issues/6 --- ttfb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ttfb b/ttfb index 06f5632..06c74b1 100755 --- a/ttfb +++ b/ttfb @@ -91,6 +91,10 @@ median() { echo $val } +show_usage() { + echo -e "Usage: ttfb [options] url [url...]\n\t-d debug\n\t-l (infers -d) log response headers. Defaults to ./curl.log\n\t-n of times to test time to first byte\n\t-v verbose output. Show response breakdown (DNS lookup, TLS handshake etc)" >&2 +} + # defaults DEBUG="" LOG="" @@ -104,7 +108,7 @@ do l) LOG="$OPTARG" ;; n) NUM_REQUESTS=$OPTARG ;; v) VERBOSE=1 ;; - \?) echo -e "Usage: ttfb [options] url [url...]\n\t-d debug\n\t-l (infers -d) log response headers. Defaults to ./curl.log\n\t-n of times to test time to first byte\n\t-v verbose output. Show response breakdown (DNS lookup, TLS handshake etc)" >&2 + \?) show_usage exit 1 ;; esac @@ -113,8 +117,8 @@ done shift $((OPTIND - 1)) # shifts away every option argument, # leaving urls as $@ -if [ -z "$1" ]; then - echo "You didn't specify any urls to fetch" +if [ -z "${1:-}" ]; then + show_usage exit 1 else URLS="$@"