Add 2019/diels-grabsch2/try.sh script
The try.sh script looks for sha512sum and shasum. If either of these are found it will use the one found (in the order of sha512sum first and shasum -a 512 second) and prog. If neither can be found it uses just prog. If one of them can be found, however, it shows how the output is the same. The prog.c was restored from prog.orig.c. Like 2019/diels-grabsch1 the purpose is no longer valid and even more problematic is the fact that the checksum value obviously would not be correct otherwise. Makefile updated instead. The README.md file has been format/typo checked. .gitignore updated - added files that try.sh script uses (though it does delete them after use).
This commit is contained in:
1 parent
4fc1683dc0
commit
51707205e9
6 files changed
+83
-16
No files matched your search
Executable
+64
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# try.sh - demonstrate IOCCC winner 2019/diels-grabsch2
|
||||
#
|
||||
|
||||
# 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
|
||||
|
||||
make CC="$CC" all >/dev/null || exit 1
|
||||
|
||||
# clear screen after compilation so that only the entry is shown
|
||||
clear
|
||||
|
||||
SHA512SUM="$(type -P sha512sum)"
|
||||
SHASUM="$(type -P shasum)"
|
||||
|
||||
if [[ -z "$SHA512SUM" && -z "$SHASUM" ]]; then
|
||||
echo "$ ./prog" 1>&2
|
||||
./prog
|
||||
elif [[ -n "$SHA512SUM" ]]; then
|
||||
echo "$ $SHA512SUM prog.c" 1>&2
|
||||
"$SHA512SUM" prog.c
|
||||
echo 1>&2
|
||||
|
||||
echo "$ ./prog" 1>&2
|
||||
./prog
|
||||
echo 1>&2
|
||||
|
||||
echo "$ $SHA512SUM prog.c | cut -f 1 -d' ' > sha512sum.txt" 1>&2
|
||||
"$SHA512SUM" prog.c | cut -f 1 -d' ' > sha512sum.txt
|
||||
echo "$ ./prog > prog.txt" 1>&2
|
||||
./prog > prog.txt
|
||||
echo 1>&2
|
||||
|
||||
echo "$ diff -s sha512sum.txt prog.txt" 1>&2
|
||||
diff -s sha512sum.txt prog.txt
|
||||
rm -f sha512sum prog.txt
|
||||
|
||||
elif [[ -n "$SHASUM" ]]; then
|
||||
# Be extra careful and don't use 'else'
|
||||
echo "$ $SHASUM -a 512 prog.c" 1>&2
|
||||
"$SHASUM" -a 512 prog.c
|
||||
echo 1>&2
|
||||
|
||||
echo "$ ./prog" 1>&2
|
||||
./prog
|
||||
echo 1>&2
|
||||
|
||||
echo "$ $SHASUM -a 512 prog.c | cut -f 1 -d' ' > sha512sum.txt" 1>&2
|
||||
"$SHASUM" -a 512 prog.c | cut -f 1 -d' ' > sha512sum.txt
|
||||
echo "$ ./prog > prog.txt" 1>&2
|
||||
./prog > prog.txt
|
||||
echo 1>&2
|
||||
|
||||
echo "$ diff -s sha512sum.txt prog.txt" 1>&2
|
||||
diff -s sha512sum.txt prog.txt
|
||||
rm -f sha512sum prog.txt
|
||||
|
||||
|
||||
fi
|
||||
Reference in new issue
Block a user