From 196a9c47f77b8bfd8b3376449d66b0be06da6d49 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 13 Feb 2016 23:34:27 +1300 Subject: A few more comments --- bin/maybe | 4 +++- bin/try | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/maybe b/bin/maybe index 43edac80..ede32dd2 100755 --- a/bin/maybe +++ b/bin/maybe @@ -65,9 +65,11 @@ if (($#)) || ! ((denom > 0)) ; then exit 2 fi -# Perform the test and print/exit appropriately +# If verbose, report the probability of the test ((verbose)) && printf '%s: Testing with probability 1/%u ... \n' \ "$self" "$denom" + +# Perform the test and print/exit appropriately if ((RANDOM < 32767/denom)) ; then ((verbose)) && printf '%s: %s\n' \ "$self" 'Success!' diff --git a/bin/try b/bin/try index 3e5af2dc..5b7378d2 100755 --- a/bin/try +++ b/bin/try @@ -89,12 +89,20 @@ trap cleanup EXIT # if we succeed on any of them declare -i ret for (( atti = 1 ; atti <= attc ; atti++ )) ; do + + # If verbose, print the number of this attempt ((verbose)) && printf '%s: Attempt %u/%u to run `%s` ...\n' \ "$self" "$atti" "$attc" "${cmd[*]}" + + # Try running the command. If it succeeds, report failure if verbose, and + # exit 0. if "${cmd[@]}" 2>>"$errbuf" ; then ((verbose)) && printf '%s: Success!\n' \ "$self" exit 0 + + # If it fails, keep the exit value, report failure, and wait until the next + # attempt. else ret=$? ((verbose)) && printf '%s: Failure!\n' \ -- cgit v1.2.3