improve shellcheck comments

This commit is contained in:
Landon Curt Noll committed 2024-03-11 09:09:21 -07:00
1 parent fa2692b0ab
commit ed822ba74b
13 files changed
+87 -84

No files matched your search

+2 -3
View File
@@ -37,9 +37,8 @@ done
# it either.
while :; do
read -r -p "Enter a value (any non-digit = quit): "
# ^-- SC2143 (style): Use grep -q instead of comparing output with [ -n .. ].
# shellcheck disable=SC2143
if [[ $(echo "$REPLY" | grep -E '\<[0-9]+\>') ]]; then
GREP_REPLY=$(echo "$REPLY" | grep -E '\<[0-9]+\>')
if [[ -z $GREP_REPLY ]]; then
make clobber CC="$CC" SIZE="$REPLY" alt >/dev/null
./shapiro.alt
else
+2 -2
View File
@@ -35,8 +35,8 @@ read -r -n 1 -p "Press any key to run: ./sicherman.alt < sicherman.alt.c | ./sic
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.
#
# SC2094 (info): Make sure not to read and write the same file in the same pipeline.
# https://www.shellcheck.net/wiki/SC2094
# shellcheck disable=SC2094
./sicherman.alt < sicherman.alt.c | ./sicherman.alt | diff -s - sicherman.alt.c
echo "Now explain any differences." 1>&2
+2 -2
View File
@@ -36,8 +36,8 @@ 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.
#
#SC2094 (info): Make sure not to read and write the same file in the same pipeline.
# https://www.shellcheck.net/wiki/SC2094
# shellcheck disable=SC2094
./sicherman < sicherman.c | ./sicherman | diff -s - sicherman.c
echo "Now explain any differences." 1>&2
+14 -12
View File
@@ -22,7 +22,10 @@ echo 1>&2
read -r -n 1 -p "Press any key to run: ./dale these files are in this directory: *: "
echo 1>&2
# We need * and do not care about dashes
#
# SC2035 (info): Use ./*glob* or -- *glob* so names with dashes won't become options.
# https://www.shellcheck.net/wiki/SC2035
# shellcheck disable=SC2035
./dale these files are in this directory: *
echo 1>&2
@@ -32,29 +35,28 @@ 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.
# This warning from ShellCheck is incorrect because we deliberately have \\n to show that
# there will be a newline printed WITH printf(1). Thus this does show correct output.
#
# SC2028 (info): echo may not expand escape sequences. Use printf.
# https://www.shellcheck.net/wiki/SC2028
# 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
# We do not care about word splitting in this case.
#
# SC2046 (warning): Quote this to prevent word splitting.
# https://www.shellcheck.net/wiki/SC2046
# shellcheck disable=SC2046
./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.
# This warning from ShellCheck is incorrect because we deliberately have \\n to show that
# there will be a newline printed WITH printf(1). Thus this does show correct output.
#
#SC2028 (info): echo may not expand escape sequences. Use printf.
# https://www.shellcheck.net/wiki/SC2028
# 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: "
+3
View File
@@ -36,7 +36,10 @@ echo 1>&2
read -r -n 1 -p "Press any key to run: ls | ./sorter > ls.sorted.txt: "
echo 1>&2
# We do want to process the ls command output.
#
# SC2012 (info): Use find instead of ls to better handle non-alphanumeric filenames.
# https://www.shellcheck.net/wiki/SC2012
# shellcheck disable=SC2012
ls | ./sorter > ls.sorted.txt
+3
View File
@@ -163,6 +163,7 @@ else
# For anything else, game in progress, do not do anything
# SC2006 (style): Use $(...) notation instead of legacy backticks `...`.
# https://www.shellcheck.net/wiki/SC2006
# shellcheck disable=SC2006
if [[ -n "`grep ':-(' ttt.alt_game.c`" ]]; then
echo
@@ -172,6 +173,7 @@ else
rm -f merlyn ttt.alt_game
else
# SC2006 (style): Use $(...) notation instead of legacy backticks `...`.
# https://www.shellcheck.net/wiki/SC2006
# shellcheck disable=SC2006
if [[ -n "`grep ':-)' ttt.alt_game.c`" ]]; then
echo
@@ -180,6 +182,7 @@ else
rm -f ttt.alt_game
else
# SC2006 (style): Use $(...) notation instead of legacy backticks `...`.
# https://www.shellcheck.net/wiki/SC2006
# shellcheck disable=SC2006
if [[ -z "`grep 'X=-. ' ttt.alt_game.c`" && -z "`grep '^. ' ttt.alt_game.c`" ]]; then
echo
+3
View File
@@ -163,6 +163,7 @@ else
# For anything else, game in progress, do not do anything
# SC2006 (style): Use $(...) notation instead of legacy backticks `...`.
# https://www.shellcheck.net/wiki/SC2006
# shellcheck disable=SC2006
if [[ -n "`grep ':-(' ttt_game.c`" ]]; then
echo
@@ -172,6 +173,7 @@ else
rm -f merlyn ttt_game
else
# SC2006 (style): Use $(...) notation instead of legacy backticks `...`.
# https://www.shellcheck.net/wiki/SC2006
# shellcheck disable=SC2006
if [[ -n "`grep ':-)' ttt_game.c`" ]]; then
echo
@@ -180,6 +182,7 @@ else
rm -f ttt_game
else
# SC2006 (style): Use $(...) notation instead of legacy backticks `...`.
# https://www.shellcheck.net/wiki/SC2006
# shellcheck disable=SC2006
if [[ -z "`grep 'X=-. ' ttt_game.c`" && -z "`grep '^. ' ttt_game.c`" ]]; then
echo
+6 -8
View File
@@ -26,13 +26,11 @@ 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.
# This warning from ShellCheck is incorrect because we deliberately have \\n to show
# that there will be a newline printed WITH printf(1). Thus this does show correct output.
#
# SC2028 (info): echo may not expand escape sequences. Use printf.
# https://www.shellcheck.net/wiki/SC2028
# 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: "
@@ -44,8 +42,8 @@ ldb_ioccc()
# 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).
#
# SC2034 (warning): i appears unused. Verify use (or export if used externally).
# https://www.shellcheck.net/wiki/SC2034
# shellcheck disable=SC2034
for i in $(seq 1 5); do
ldb_file /etc/passwd
+4 -5
View File
@@ -15,12 +15,11 @@ 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.
# This warning from ShellCheck is incorrect because we don't want them to be expanded.
# This does show correct output.
#
# SC2028 (info): echo may not expand escape sequences. Use printf.
# https://www.shellcheck.net/wiki/SC2028
# 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"
+4 -5
View File
@@ -15,12 +15,11 @@ make CC="$CC" all >/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.
# This warning from ShellCheck is incorrect because we don't want them to be expanded.
# This does show correct output.
#
# SC2028 (info): echo may not expand escape sequences. Use printf.
# https://www.shellcheck.net/wiki/SC2028
# 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"
+28 -42
View File
@@ -18,24 +18,20 @@ 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.
# This warning from ShellCheck is incorrect because we don't want to expand escape sequences.
# Thus this does show correct output.
#
# SC2028 (info): echo may not expand escape sequences. Use printf.
# https://www.shellcheck.net/wiki/SC2028
# 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.
# This warning from ShellCheck is incorrect because we don't want to expand escape sequences.
# Thus this does show correct output.
#
# SC2028 (info): echo may not expand escape sequences. Use printf.
# https://www.shellcheck.net/wiki/SC2028
# shellcheck disable=SC2028
echo "$ echo '
(\f\g\x
@@ -46,13 +42,11 @@ 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.
# This warning from ShellCheck is incorrect because we don't want to expand escape sequences.
# Thus this does show correct output.
#
# SC2028 (info): echo may not expand escape sequences. Use printf.
# https://www.shellcheck.net/wiki/SC2028
# shellcheck disable=SC2028
echo '
(\f\g\x
@@ -62,35 +56,29 @@ 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.
# This warning from ShellCheck is incorrect because we don't want to expand escape sequences.
# Thus this does show correct output.
#
# SC2028 (info): echo may not expand escape sequences. Use printf.
# https://www.shellcheck.net/wiki/SC2028
# 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.
# This warning from ShellCheck is incorrect because we don't want to expand escape sequences.
# Thus this does show correct output.
#
# SC2028 (info): echo may not expand escape sequences. Use printf.
# https://www.shellcheck.net/wiki/SC2028
# 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.
# This warning from ShellCheck is incorrect because we don't want to expand escape sequences.
# Thus this does show correct output.
#
# SC2028 (info): echo may not expand escape sequences. Use printf.
# https://www.shellcheck.net/wiki/SC2028
# shellcheck disable=SC2028
echo "$ echo '
(Y\f\n
@@ -102,13 +90,11 @@ 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.
# This warning from ShellCheck is incorrect because we don't want to expand escape sequences.
# Thus this does show correct output.
#
# SC2028 (info): echo may not expand escape sequences. Use printf.
# https://www.shellcheck.net/wiki/SC2028
# shellcheck disable=SC2028
echo '(Y\f\n
((= n 0)
+3
View File
@@ -36,7 +36,10 @@ echo 1>&2
echo "$ ./westley.sort < westley.c 2>/dev/null | diff -s - westley.c"
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
# There isn't a read and write problem.
#
# SC2094 (info): Make sure not to read and write the same file in the same pipeline.
# https://www.shellcheck.net/wiki/SC2094
# shellcheck disable=SC2094
./westley.sort < westley.c 2>/dev/null | diff -s - westley.c | less -rEXFK
echo 1>&2
+13 -5
View File
@@ -6,7 +6,8 @@ if [[ "$#" -lt 2 ]]; then
fi
COUNT=$1; shift
# ^--^ SC2124 (warning): Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.
# SC2124 (warning): Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.
# https://www.shellcheck.net/wiki/SC2124
# shellcheck disable=SC2124
CMD="$@"
@@ -16,20 +17,27 @@ USER=0
REAL=0
while [[ $N -lt $COUNT ]]; do
# ^---^ SC2086 (info): Double quote to prevent globbing and word splitting.
# 'fixing' this will break the script so we disable it:
#
# SC2086 (info): Double quote to prevent globbing and word splitting.
# https://www.shellcheck.net/wiki/SC2086
# shellcheck disable=SC2086
TIME=$( { /usr/bin/time -l $CMD >/dev/null; } 2>&1 | head -n 1 )
# ^---^ SC2086 (info): Double quote to prevent globbing and word splitting.
# 'fixing' this will break the script so we disable it:
#
# SC2086 (info): Double quote to prevent globbing and word splitting.
# https://www.shellcheck.net/wiki/SC2086
# shellcheck disable=SC2086
REAL="$REAL + $(echo $TIME | cut -d' ' -f1)"
# ^---^ SC2086 (info): Double quote to prevent globbing and word splitting.
# 'fixing' this will break the script so we disable it:
#
# SC2086 (info): Double quote to prevent globbing and word splitting.
# shellcheck disable=SC2086
USER="$USER + $(echo $TIME | cut -d' ' -f3)"
# ^---^ SC2086 (info): Double quote to prevent globbing and word splitting.
# 'fixing' this will break the script so we disable it:
#
# SC2086 (info): Double quote to prevent globbing and word splitting.
# https://www.shellcheck.net/wiki/SC2086
# shellcheck disable=SC2086
SYS="$SYS + $(echo $TIME | cut -d' ' -f5)"
((N++))