From 37d43c8e18a5076ddf367c5936e4da50b43ae5dd Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 21 Jan 2024 04:54:21 -0800 Subject: [PATCH 1/9] Deal with shellcheck warnings in 1985/sicherman In these scripts, try.sh and try.alt.sh, the warning triggered is entirely incorrect and not a problem so they are now disabled. --- 1985/sicherman/try.alt.sh | 5 +++++ 1985/sicherman/try.sh | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/1985/sicherman/try.alt.sh b/1985/sicherman/try.alt.sh index de1e3ebcc..90ac47ddc 100755 --- a/1985/sicherman/try.alt.sh +++ b/1985/sicherman/try.alt.sh @@ -33,5 +33,10 @@ echo 1>&2 read -r -n 1 -p "Press any key to run: ./sicherman.alt < sicherman.alt.c | ./sicherman.alt | diff -s - sicherman.alt.c: " echo 1>&2 +# This warning from ShellCheck is incorrect: +# +# SC2094 (info): Make sure not to read and write the same file in the same pipeline. +# +# shellcheck disable=SC2094 ./sicherman.alt < sicherman.alt.c | ./sicherman.alt | diff -s - sicherman.alt.c echo "Now explain any differences." 1>&2 diff --git a/1985/sicherman/try.sh b/1985/sicherman/try.sh index 1192b28b5..b515bd274 100755 --- a/1985/sicherman/try.sh +++ b/1985/sicherman/try.sh @@ -33,5 +33,11 @@ echo 1>&2 read -r -n 1 -p "Press any key to run: ./sicherman < sicherman.c | ./sicherman | diff -s - sicherman.c: " echo 1>&2 + +# This warning from ShellCheck is incorrect: +# +# SC2094 (info): Make sure not to read and write the same file in the same pipeline. +# +# shellcheck disable=SC2094 ./sicherman < sicherman.c | ./sicherman | diff -s - sicherman.c echo "Now explain any differences." 1>&2 From e73b084d20c10d3fc0ec55b94998e952827eb7b2 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 21 Jan 2024 04:58:32 -0800 Subject: [PATCH 2/9] Deal with shellcheck warnings in 1988/dale In these scripts, try.sh and try.alt.sh, the warning triggered is entirely incorrect and not a problem so they are now disabled. The comments explain why this is. --- 1988/dale/try.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/1988/dale/try.sh b/1988/dale/try.sh index 132abe136..9b5689add 100755 --- a/1988/dale/try.sh +++ b/1988/dale/try.sh @@ -32,6 +32,14 @@ echo "Why do they differ in the format from the above command? Finally how can y echo "get the more likely desired behaviour?" 1>&2 echo 1>&2 echo 1>&2 +# This warning from ShellCheck is incorrect: +# +# SC2028 (info): echo may not expand escape sequences. Use printf. +# +# because we deliberately have \\n to show that there will be a newline printed +# WITH printf(1). Thus this does show correct output. +# +# shellcheck disable=SC2028 echo "$ ./dale \$(printf "the following files exist in this directory:\\n%s\\n" *)" read -r -n 1 -p "Press any key to continue: " echo 1>&2 @@ -40,6 +48,14 @@ echo 1>&2 ./dale $(printf "the following files exist in this directory:\n%s\n" *) echo 1>&2 +# This warning from ShellCheck is incorrect: +# +# SC2028 (info): echo may not expand escape sequences. Use printf. +# +# because we deliberately have \\n to show that there will be a newline printed +# WITH printf(1). Thus this does show correct output. +# +# shellcheck disable=SC2028 echo "$ ./dale \"\$(printf \"the following files exist in this directory:\\n%s\\n\" *)\"" read -r -n 1 -p "Press any key to continue: " echo 1>&2 From e227f77f594dd144b64eedb477e187c8f5c9659e Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 21 Jan 2024 05:02:49 -0800 Subject: [PATCH 3/9] Deal with shellcheck warnings in 1993/plummer This was only in try.sh: SLEEP is not needed which is why the error was not detected. SLEEP is only relevant to the alt code. But the try.alt.sh was updated to make it shorter for assigning the default: [[ -z "$SLEEP" ]] && SLEEP=1000 1000 is the default in the Makefile. --- 1993/plummer/try.alt.sh | 4 +--- 1993/plummer/try.sh | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/1993/plummer/try.alt.sh b/1993/plummer/try.alt.sh index 9c4f532fe..5a68767cb 100755 --- a/1993/plummer/try.alt.sh +++ b/1993/plummer/try.alt.sh @@ -12,9 +12,7 @@ fi # let user change the sleep duration if they wish # -if [[ -z "$SLEEP" ]]; then - SLEEP=1000 -fi +[[ -z "$SLEEP" ]] && SLEEP=1000 # let user change the number if they wish to # diff --git a/1993/plummer/try.sh b/1993/plummer/try.sh index e1dde1689..73f2edd83 100755 --- a/1993/plummer/try.sh +++ b/1993/plummer/try.sh @@ -26,7 +26,7 @@ else ARG="$2" fi -make CC="$CC" SLEEP="$SLEEP" all >/dev/null || exit 1 +make CC="$CC" all >/dev/null || exit 1 # clear screen after compilation so that only the entry is shown clear From 61aa66443ff7ad1dec3919227c09e21338fc8740 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 21 Jan 2024 05:08:18 -0800 Subject: [PATCH 4/9] Deal with shellcheck for 1994/ldb/try.sh --- 1994/ldb/try.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/1994/ldb/try.sh b/1994/ldb/try.sh index e0471b94f..27c6bdf4c 100755 --- a/1994/ldb/try.sh +++ b/1994/ldb/try.sh @@ -26,6 +26,14 @@ ldb_file() ldb_ioccc() { + # This warning from ShellCheck is incorrect: + # + # SC2028 (info): echo may not expand escape sequences. Use printf. + # + # because we deliberately have \\n to show that there will be a newline printed + # WITH printf(1). Thus this does show correct output. + # + # shellcheck disable=SC2028 echo "$ printf \"The International Obfuscated C Code Contest\\nBest One-liner\\nby Laurion Burchall\" | ./ldb" read -r -n 1 -p "Press any key to continue: " echo 1>&2 @@ -33,6 +41,12 @@ ldb_ioccc() echo 1>&2 } +# This warning from ShellCheck is irrelevant as we only use 'i' as an iterator +# to do the commands a number of times: +# +# SC2034 (warning): i appears unused. Verify use (or export if used externally). +# +# shellcheck disable=SC2034 for i in $(seq 1 5); do ldb_file /etc/passwd ldb_ioccc From cdc7212e1b0b25fedd0777fe52edea5b8c7acfc3 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 21 Jan 2024 05:13:44 -0800 Subject: [PATCH 5/9] Deal with shellcheck warnings in 1995/garry --- 1995/garry/try.alt.sh | 9 ++++++++- 1995/garry/try.sh | 12 +++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/1995/garry/try.alt.sh b/1995/garry/try.alt.sh index 29d812912..3fa9e91b9 100755 --- a/1995/garry/try.alt.sh +++ b/1995/garry/try.alt.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash # # try.alt.sh - demonstrate IOCCC winner 1995/garry alt code # @@ -15,6 +15,13 @@ make CC="$CC" alt >/dev/null || exit 1 # clear screen after compilation so that only the entry is shown clear +# This warning from ShellCheck is incorrect: +# +# SC2028 (info): echo may not expand escape sequences. Use printf. +# +# because we don't want them to be expanded. This does show correct output. +# +# shellcheck disable=SC2028 echo "$ EXAMPLEON=\"\33\133\61\73\67\155\"; EXAMPLEOFF=\"\33\133\155\"; DOLLAR=\"$\"" 1>&2 EXAMPLEON="\33\133\61\73\67\155" EXAMPLEOFF="\33\133\155" diff --git a/1995/garry/try.sh b/1995/garry/try.sh index 1d3175889..e5548f933 100755 --- a/1995/garry/try.sh +++ b/1995/garry/try.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash # # try.sh - demonstrate IOCCC winner 1995/garry # @@ -15,8 +15,14 @@ make CC="$CC" all >/dev/null || exit 1 # clear screen after compilation so that only the entry is shown clear - -echo "$ EXAMPLEON=\"\33\133\61\73\67\155\"; EXAMPLEOFF=\"\33\133\155\"; DOLLAR=\"$\"" 1>&2 +# This warning from ShellCheck is incorrect: +# +# SC2028 (info): echo may not expand escape sequences. Use printf. +# +# because we don't want them to be expanded. This does show correct output. +# +# shellcheck disable=SC2028 +echo "$ EXAMPLEON=\"\\33\133\61\73\67\155\"; EXAMPLEOFF=\"\33\133\155\"; DOLLAR=\"$\"" 1>&2 EXAMPLEON="\33\133\61\73\67\155" EXAMPLEOFF="\33\133\155" DOLLAR="$" From 2a1623b5c16e1a3ffc20414ea4f76d7f613aa750 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 21 Jan 2024 05:15:07 -0800 Subject: [PATCH 6/9] Deal with shellcheck in 1998/df/try.sh --- 1998/df/try.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1998/df/try.sh b/1998/df/try.sh index 284ebd4be..bf0113cca 100755 --- a/1998/df/try.sh +++ b/1998/df/try.sh @@ -15,7 +15,7 @@ make CC="$CC" all >/dev/null || exit 1 # clear screen after compilation so that only the entry is shown clear -while [[ 1 ]]; do +while :; do read -r -n 1 -p "Press any key to run ./df or 'q' to quit: " echo 1>&2 if [[ "$REPLY" = "q" || "$REPLY" = "Q" ]]; then From a576f1e45c1b1480b20d403d7ca06a36bf8b4657 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 21 Jan 2024 05:18:30 -0800 Subject: [PATCH 7/9] Deal with shellcheck warnings in 1988/fanf/try.sh --- 1998/fanf/try.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/1998/fanf/try.sh b/1998/fanf/try.sh index 24504d93b..9c244f52d 100755 --- a/1998/fanf/try.sh +++ b/1998/fanf/try.sh @@ -17,9 +17,26 @@ clear read -r -n 1 -p "Press any key to run: echo '((\a(\b(\c(d)))) e)' | ./fanf: " echo 1>&2 + +# This warning from ShellCheck is incorrect: +# +# SC2028 (info): echo may not expand escape sequences. Use printf. +# +# because we don't want to expand escape sequences. Thus this does show correct +# output. +# +# shellcheck disable=SC2028 echo '((\a(\b(\c(d)))) e)' | ./fanf echo 1>&2 +# This warning from ShellCheck is incorrect: +# +# SC2028 (info): echo may not expand escape sequences. Use printf. +# +# because we don't want to expand escape sequences. Thus this does show correct +# output. +# +# shellcheck disable=SC2028 echo "$ echo ' (\f\g\x ( @@ -28,6 +45,15 @@ echo "$ echo ' )'|./fanf" 1>&2 read -r -n 1 -p "Press any key to continue: " echo 1>&2 + +# This warning from ShellCheck is incorrect: +# +# SC2028 (info): echo may not expand escape sequences. Use printf. +# +# because we don't want to expand escape sequences. Thus this does show correct +# output. +# +# shellcheck disable=SC2028 echo ' (\f\g\x ( @@ -36,13 +62,36 @@ echo ' )'|./fanf echo 1>&2 - +# This warning from ShellCheck is incorrect: +# +# SC2028 (info): echo may not expand escape sequences. Use printf. +# +# because we don't want to expand escape sequences. Thus this does show correct +# output. +# +# shellcheck disable=SC2028 echo "$ echo '(\f(\f\g\x( (f((\a(g(b))) e)) (g x) ) K K z))' | ./fanf" 1>&2 read -r -n 1 -p "Press any key to continue: " echo 1>&2 +# This warning from ShellCheck is incorrect: +# +# SC2028 (info): echo may not expand escape sequences. Use printf. +# +# because we don't want to expand escape sequences. Thus this does show correct +# output. +# +# shellcheck disable=SC2028 echo '(\f(\f\g\x( (f((\a(g(b))) e)) (g x) ) K K z))' | ./fanf echo 1>&2 +# This warning from ShellCheck is incorrect: +# +# SC2028 (info): echo may not expand escape sequences. Use printf. +# +# because we don't want to expand escape sequences. Thus this does show correct +# output. +# +# shellcheck disable=SC2028 echo "$ echo ' (Y\f\n ((= n 0) @@ -53,6 +102,14 @@ echo "$ echo ' read -r -n 1 -p "Press any key to continue: " echo 1>&2 +# This warning from ShellCheck is incorrect: +# +# SC2028 (info): echo may not expand escape sequences. Use printf. +# +# because we don't want to expand escape sequences. Thus this does show correct +# output. +# +# shellcheck disable=SC2028 echo '(Y\f\n ((= n 0) 1 From bf3ebe435be9a8f2cade24e4910474a08a9cb515 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 21 Jan 2024 05:21:01 -0800 Subject: [PATCH 8/9] Deal with shellcheck warnings in 2000/rince/try.sh --- 2000/rince/try.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/2000/rince/try.sh b/2000/rince/try.sh index 375f04f1d..2ab1eec5e 100755 --- a/2000/rince/try.sh +++ b/2000/rince/try.sh @@ -22,6 +22,14 @@ echo 1>&2 read -r -n 1 -p "Press any key to run: ./rince 0.001 $(./dmy2jd 7.8 1 1610): " echo 1>&2 + +# ShellCheck is incorrect about: +# +# SC2046 (warning): Quote this to prevent word splitting. +# +# because we actually want word splitting. +# +# shellcheck disable=SC2046 ./rince 0.001 $(./dmy2jd 7.8 1 1610) echo 1>&2 @@ -42,15 +50,36 @@ echo 1>&2 read -r -n 1 -p "Press any key to run: ./rince 0 $(./dmy2jd 7.8 1 1610): " echo 1>&2 +# ShellCheck is incorrect about: +# +# SC2046 (warning): Quote this to prevent word splitting. +# +# because we actually want word splitting. +# +# shellcheck disable=SC2046 ./rince 0 $(./dmy2jd 7.8 1 1610) echo 1>&2 read -r -n 1 -p "Press any key to run: ./rince 0 $(./dmy2jd 8.8 1 1610): " echo 1>&2 +# ShellCheck is incorrect about: +# +# SC2046 (warning): Quote this to prevent word splitting. +# +# because we actually want word splitting. +# +# shellcheck disable=SC2046 ./rince 0 $(./dmy2jd 8.8 1 1610) echo 1>&2 read -r -n 1 -p "Press any key to run: ./rince 0 $(./dmy2jd 10.8 1 1610): " echo 1>&2 +# ShellCheck is incorrect about: +# +# SC2046 (warning): Quote this to prevent word splitting. +# +# because we actually want word splitting. +# +# shellcheck disable=SC2046 ./rince 0 $(./dmy2jd 10.8 1 1610) echo 1>&2 From 38ed2dcd45455152193f5578372a1430ed387afd Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 21 Jan 2024 05:26:29 -0800 Subject: [PATCH 9/9] Deal with shellcheck warnings in 2000/bmeyer --- 2000/bmeyer/try.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/2000/bmeyer/try.sh b/2000/bmeyer/try.sh index d2c59583c..aaa4f6869 100755 --- a/2000/bmeyer/try.sh +++ b/2000/bmeyer/try.sh @@ -19,13 +19,22 @@ clear # be determined: we just use a default value. # # try getting the columns the simple way first: tput cols -COLUMNS="$(tput cols)" -# ^--^ SC2181 (style): Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?. +COLUMNS="$(tputs cols)" +# In this case we might be able to get away with resolving this ShellCheck +# warning: +# +# SC2181 (style): Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?. +# +# but we want to assign the value to COLUMNS and at the same time make sure tput +# worked. Thus we disable this warning. +# # shellcheck disable=SC2181 if [[ "$?" -ne 0 ]]; then # if tput failed for any reason try stty(1) with awk(1): # Disable this warning of shellcheck as it's wrong: awk needs single quotes. - # ^-----------^ SC2016 (info): Expressions don't expand in single quotes, use double quotes for that. + # + # SC2016 (info): Expressions don't expand in single quotes, use double quotes for that. + # # shellcheck disable=SC2016 COLUMNS="$(stty size|awk '{print $NF}')" @@ -74,7 +83,7 @@ echo 1>&2 ./glicbawls "$COLUMNS" < lavabus.pgm > lavabus.glic echo 1>&2 -read -r -n 1 -p "Press any key to run: ./glicbawls -2 "$COLUMNS" < lavabus.pgm > lavabus.glic2: " +read -r -n 1 -p "Press any key to run: ./glicbawls -2 $COLUMNS < lavabus.pgm > lavabus.glic2: " echo 1>&2 ./glicbawls -2 "$COLUMNS" < lavabus.pgm > lavabus.glic2 echo 1>&2