From 7a0b8af3421d82d744f8581d62c253f75d65fb1c Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 4 Oct 2026 05:32:25 -0700 Subject: [PATCH] Clarify and improve 2025/yang1/try.sh (If Don Yang disagrees with any of this I am quite fine in not having this btw). The script now checks if ruby is installed prior to running the ruby commands. The same is done for perl. (Both use type -P). The message that says '0 to quit' might suggest to quit the script but it does not. In fact it means to move to the next step so it now says 'to go to the next step'. This should help clarify what is happening and it might also (though not completely and very possibly not - maybe this should be added as a little notice before?) help users see that it's looping with the same procedure until one enters 0 (at the appropriate prompt). The 'to go to next step' might also help people who are not paying attention or who are sleeping (or not awake enough). --- 2025/yang1/try.sh | 48 ++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/2025/yang1/try.sh b/2025/yang1/try.sh index e00113ed69..8f10dcb2b2 100755 --- a/2025/yang1/try.sh +++ b/2025/yang1/try.sh @@ -36,25 +36,30 @@ echo 1>&2 seq 5 | ./prog -2 echo 1>&2 -# Demonstrate chop function +# Demonstrate chop function if ruby is installed # -read -r -n 1 -p "Press any key to see the usage message for: ruby prog.c " -echo 1>&2 -echo 1>&2 -ruby prog.c -echo 1>&2 - -read -r -n 1 -p "Press any key to run: seq 5 | ruby prog.c 2 " -echo 1>&2 -echo 1>&2 -seq 5 | ruby prog.c 2 -echo 1>&2 - -read -r -n 1 -p "Press any key to run: seq 5 | ruby prog.c -2 " -echo 1>&2 -echo 1>&2 -seq 5 | ruby prog.c -2 -echo 1>&2 +RUBY="$(type -P ruby)" +if [[ -n "$RUBY" ]]; then + read -r -n 1 -p "Press any key to see the usage message for: ruby prog.c " + echo 1>&2 + echo 1>&2 + "$RUBY" prog.c + echo 1>&2 + + read -r -n 1 -p "Press any key to run: seq 5 | ruby prog.c 2 " + echo 1>&2 + echo 1>&2 + seq 5 | "$RUBY" prog.c 2 + echo 1>&2 + + read -r -n 1 -p "Press any key to run: seq 5 | ruby prog.c -2 " + echo 1>&2 + echo 1>&2 + seq 5 | "$RUBY" prog.c -2 + echo 1>&2 +else + echo "NOTICE: ruby was not found so we have skipped some commands." 1>&2 +fi # Demonstrate head function # @@ -146,7 +151,7 @@ ${CC} prog_generate.c -o prog_generate && ./prog_generate > prog_classify.c while true; do while true; do - read -r -p "Enter an integer between 1 and 9999, or 0 to quit: " number + read -r -p "Enter an integer between 1 and 9999, or 0 to go to next step: " number echo 1>&2 if ! [[ "$number" =~ ^[0-9]+$ ]]; then @@ -180,12 +185,13 @@ while true; do echo 1>&2 done -# Final parting messages +# Final parting messages if perl installed # +PERL="$(type -P perl)" read -r -n 1 -p "Press any key to run: perl prog.c " echo 1>&2 echo 1>&2 -perl prog.c +"$PERL" prog.c echo 1>&2 read -r -n 1 -p "Press any key to run: ./bf prog.c "