From 71299bf8a70b421508f034ef1f66ab7715426ec5 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Mon, 5 Feb 2024 05:03:47 -0800 Subject: [PATCH] Further improve 2000/schneiderwent/try.sh Now allows one to override how long to sleep and how many iterations to go through. It is an error if non positive values are specified. --- 2000/schneiderwent/README.md | 9 ++++++++ 2000/schneiderwent/try.sh | 45 ++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/2000/schneiderwent/README.md b/2000/schneiderwent/README.md index 10af15555..fc4cb01f6 100644 --- a/2000/schneiderwent/README.md +++ b/2000/schneiderwent/README.md @@ -28,6 +28,15 @@ paint dry :-) ) you might also try: ./try.sh ``` +Alternatively, you can check on it later on, to see all the entry does. Or if +you wish to make it run faster, you can override how long it sleeps per +iterations and how many iterations it runs. For instance to make it sleep only +30 seconds and run only twice: + +```sh +SLEEP=30 ITERATIONS=2 ./try.sh +``` + ## Judges' remarks: diff --git a/2000/schneiderwent/try.sh b/2000/schneiderwent/try.sh index 5af75696b..54ab3719a 100755 --- a/2000/schneiderwent/try.sh +++ b/2000/schneiderwent/try.sh @@ -6,23 +6,50 @@ # make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it # this way allows us to have the user specify a different compiler in an easy # way. -if [[ -z "$CC" ]]; then - CC="cc" -fi +[[ -z "$CC" ]] && CC="cc" make CC="$CC" all >/dev/null || exit 1 # clear screen after compilation so that only the entry is shown clear -echo "This will take a long time to run to completion: " 1>&2 +# get the number of seconds to sleep in between runs (def: 60) +[[ -z "$SLEEP" ]] && SLEEP=60 +# verify it's a positive number: +echo "$SLEEP" | grep -qE '^[0-9]+' +if [[ "${PIPESTATUS[1]}" -ne 0 ]]; then + echo "SLEEP value not a positive number, fix and run again." + exit 1 +fi +# get the number of iterations to run (default: 60) +[[ -z "$ITERATIONS" ]] && ITERATIONS=60 +# verify it's a positive number: +echo "$ITERATIONS" | grep -qE '^[0-9]+' +if [[ "${PIPESTATUS[1]}" -ne 0 ]]; then + echo "ITERATIONS value not a positive number, fix and run again." + exit 1 +fi + +echo "If you did not override \$SLEEP and \$ITERATIONS this will take a long" 1>&2 +echo "time to run to completion: approximately one hour. If you do not care to" 1>&2 +echo "wait such a long time, which we presume is probably quite likely, you" 1>&2 +echo "you might wish to run this entry like the following: " 1>&2 +echo 1>&2 +echo " ./schneiderwent" 1>&2 +echo " ./schneiderwent schneiderwent.data" 1>&2 +echo 1>&2 +echo "at various times throughout the day, preferably at different" 1>&2 +echo "minutes of the hours." 1>&2 +echo 1>&2 +echo "Alternatively, you can leave this running in a console tab for an hour" 1>&2 +echo "and look back at it later, so that you can see all the entry does." 1>&2 +echo 1>&2 +read -r -n 1 -p "Press any key to start: " +echo 1>&2 i=0 -while [[ "$i" -lt 60 ]]; do +while [[ "$i" -lt "$ITERATIONS" ]]; do ./schneiderwent ./schneiderwent schneiderwent.data - sleep 60 + sleep "$SLEEP" ((i++)) done - - -