-
-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathtry.sh
More file actions
executable file
·49 lines (40 loc) · 1.54 KB
/
Copy pathtry.sh
File metadata and controls
executable file
·49 lines (40 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
#
# try.sh - demonstrate IOCCC entry 2005/mikeash
#
# 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
read -r -n 1 -p "Press any key to run: ./mikeash < mikeash.c (space = next page, q = quit): "
echo 1>&2
./mikeash < mikeash.c | less -rEXFK
echo 1>&2
echo 1>&2
read -r -n 1 -p "Press any key to run: ./mikeash < mikeash.c | diff -s - mikeash.c: "
echo 1>&2
# We're not reading and writing to the same file at all.
#
# 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
./mikeash < mikeash.c | diff -s - mikeash.c
echo 1>&2
echo "For the next two commands we will add a newline after the command's output" 1>&2
echo "for your convenience as they will not print a newline themselves." 1>&2
echo 1>&2
echo "The next command should show: \"4." 1>&2
read -r -n 1 -p "Press any key to run: echo '(format t \"~s\" (+ 2 2 ))' | ./mikeash: "
echo 1>&2
echo '(format t "~s" (+ 2 2 ))' | ./mikeash
echo 1>&2
echo "The next command will evaluate the expression: (2+2) * (5 - 9/3), giving 8\"." 1>&2
read -r -n 1 -p "Press any key to run: echo '(format t \"~s\" (* (+ 2 2 ) (- 5 (/ 9 3 ))))' | ./mikeash: "
echo 1>&2
echo '(format t "~s" (* (+ 2 2 ) (- 5 (/ 9 3 ))))' | ./mikeash
echo 1>&2