-
-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathtry.sh
More file actions
executable file
·97 lines (90 loc) · 4.75 KB
/
try.sh
File metadata and controls
executable file
·97 lines (90 loc) · 4.75 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
#
# try.sh - demonstration of YYYY/XXX <<=== The IOCCC Judges will replace this line
# XXX - remove text below, including this line - XXX
# XXX - - XXX
# XXX - NOTE: please remove all "XXX - ... - XXX" lines - XXX
# XXX - - XXX
# XXX - try.sh example version: 30.0.0 2026-04-21 - XXX
# XXX - - XXX
# XXX - remove text above, including this line - XXX
# 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.
#
# XXX - remove text below, including this line - XXX
# XXX - - XXX
# XXX - if you need CC to be something else, say clang, then change cc - XXX
# XXX - to whatever you need. - XXX
# XXX - If you need other variables you can also set them in whatever way - XXX
# XXX - you need; this is a good method, however, in cases where it's OK - XXX
# XXX - to let the user redefine it. - XXX
# XXX - - XXX
# XXX - remove text above, including this line - XXX
[[ -z "$CC" ]] && CC="cc"
# make sure the program has been built
#
# XXX - remove text below, including this line - XXX
# XXX - - XXX
# XXX - make sure to compile the program, using make all! - XXX
# XXX - if you need to build the alt code for the try.sh script, - XXX
# XXX - then change the 'all' to 'all alt' in the below command. - XXX
# XXX - Later, if the submission wins, it can be changed to 'everything'. - XXX
# XXX - - XXX
# XXX - remove text above, including this line - XXX
MAKE=$(command -v gmake)
${MAKE:=make} CC="$CC" all >/dev/null || exit 1
# clear the screen
#
clear
# XXX - remove text below, including this line - XXX
# XXX - - XXX
# XXX - NOTE: You can include more than one command line, including pipes. - XXX
# XXX - - XXX
# XXX - It is good to use the shell built-in read(1) to let the user know - XXX
# XXX - what is about to be executed. We suggest a double echo after the - XXX
# XXX - use of the shell built-in read(1) to help separate the prompt from - XXX
# XXX - any output your code may produce. We also suggest an echo after - XXX
# XXX - any execution to help separate any output from the next prompt or - XXX
# XXX - from the end of the script. - XXX
# XXX - - XXX
# XXX - We recommend sending echo's (both empty lines and messages) to - XXX
# XXX - stderr as this makes it easier to separate script output (stderr) - XXX
# XXX - from any stdout of your program. However, do NOT send the shell - XXX
# XXX - built-in read(1) to stderr. - XXX
# XXX - - XXX
# XXX - You may modify the command based on your program and you may have - XXX
# XXX - more than one invocation. - XXX
# XXX - - XXX
# XXX - Examples follow. - XXX
# XXX - - XXX
# XXX - For more examples, see the try.sh scripts under most recent - XXX
# XXX - IOCCC year's directory. - XXX
# XXX - - XXX
# XXX - Remove/expand sections as needed: these are just examples. - XXX
# XXX - - XXX
# XXX - remove text above, including this line - XXX
# try the program
#
read -r -n 1 -p "Press any key to run: ./prog: "
echo 1>&2
echo 1>&2
./prog
echo 1>&2
# try the program with args
#
# XXX - remove text below, including this line - XXX
# XXX - - XXX
# XXX - Notice that the echo below is also sent to stderr, and there is an - XXX
# XXX - empty echo written to stderr before the shell built-in read(1) call - XXX
# XXX - - XXX
# XXX - remove text above, including this line - XXX
echo 'Let us try another example. Observe the line count of output and the last line of data!' 1>&2
echo 1>&2
read -r -n 1 -p "Press any key to run: date | ./prog some command line | LC_ALL=C sort > data: "
echo 1>&2
echo 1>&2
rm -f data
date | ./prog some command line | LC_ALL=C sort > data
wc -l < data
tail -n 1 data
echo 1>&2