Improve 1998/bas2/try.sh

This commit is contained in:
Cody Boone Ferguson committed 2024-01-19 06:26:51 -08:00
1 parent 30492282bd
commit ee5d57352f
2 files changed
+23 -7

No files matched your search

+2
View File
@@ -19,6 +19,8 @@ echo text | ./bas2
./try.sh
./try.sh "foo bar" "baz" "IOCCC 1998/bas2" README.md
./try.sh try.sh "bas2.c" bas2.orig.c
```
+21 -7
View File
@@ -15,30 +15,44 @@ make CC="$CC" all >/dev/null || exit 1
# clear screen after compilation so that only the entry is shown
clear
echo "$ ./bas2 < bas2.c" 1>&2
read -r -n 1 -p "Press any key to run: ./bas2 < bas2.c: "
echo 1>&2
./bas2 < bas2.c
echo 1>&2
echo "$ ./bas2 < README.md" 1>&2
read -r -n 1 -p "Press any key to run: ./bas2 < README.md: "
echo 1>&2
./bas2 < README.md
echo 1>&2
echo "$ ./bas2 < Makefile" 1>&2
read -r -n 1 -p "Press any key to run: ./bas2 < Makefile: "
echo 1>&2
./bas2 < Makefile
echo 1>&2
echo "$ echo foo bar baz | ./bas2" 1>&2
read -r -n 1 -p "Press any key to run: echo foo bar baz | ./bas2: "
echo 1>&2
echo foo bar baz | ./bas2
echo 1>&2
echo "$ cat README.md Makefile bas2.c | ./bas2" 1>&2
read -r -n 1 -p "Press any key to run: cat README.md Makefile bas2.c | ./bas2: "
echo 1>&2
cat README.md Makefile bas2.c | ./bas2
echo 1>&2
# while we have an arg check if it's a file. If it is a regular file that is
# readable feed it to the program; otherwise act as if it's a string.
while [[ "$#" -gt 0 ]]; do
if [[ -f "$1" && -r "$1" ]]; then
echo "$ ./bas2 < $1" 1>&2
read -r -n 1 -p "Press any key to run: ./bas2 < $1: "
echo 1>&2
./bas2 < "$1"
echo 1>&2
else
echo "$ echo $1 | ./bas2" 1>&2
read -r -n 1 -p "Press any key to run: echo $1 | ./bas2: "
echo 1>&2
echo "$1" | ./bas2
echo 1>&2
fi
shift 1
done