1 #!/bin/sh
2
3 # Shell script #2 used to test MINIX.
4 # smx doesn't support comilation, so the script has been tailored.
5 # Comment out compilation, running of compiled program, and running strings
6 # on a.out.
7
8 PATH=:/bin:/usr/bin
9 export PATH
10
11 # CC="exec cc -wo -F" # nonstandard flags for ACK :-(
12 CC=cc
13
14 ARCH=`arch`
15
16 echo -n "Shell test 2 "
17 rm -rf DIR_SH2
18 mkdir DIR_SH2 # all files are created here
19 cd DIR_SH2
20
21 cat >file <<END
22 The time has come the walrus said to talk of many things
23 Of shoes and ships and sealing wax of cabbages and kings
24 Of why the sea is boiling hot and whether pigs have wings
25 END
26 f=file # scratch file
27
28 cat >makefile <<END # create a makefile
29 all: x.c
30 @$CC x.c >/dev/null 2>&1
31 END
32 cat >x.c <<END # create a C program
33 #include <stdio.h>
34 char s[] = {"MS-DOS: Just say no"}; /* used by strings later */
35 main()
36 {
37 int i;
38 for (i = 15; i < 18; i++) printf("%d\\n",i*i);
39 }
40 END
41
42 cat >answer <<END # C program should produce these results
43 225
44 256
45 289
46 END
47
48 #make
49 #if test -f a.out; then : ; else echo Compilation failed; fi
50 #a.out >x
51 #if test -f x; then : ; else echo No compiler output; fi
52 #if cmp -s x answer; then : ; else echo Error in cc test 1; fi
53
54 #Test chmod
55 echo Hi there folks >x
56 if test -r x; then : ; else echo Error on chmod test 1; fi
57 chmod 377 x
58 if test -r x; then test -w / || echo Error on chmod test 2; fi
59 chmod 700 x
60 if test -r x; then : ; else echo Error on chmod test 3; fi
61
62 #Test cut
63 cat >x <<END # x is a test file with 3 columns
64 1 white bunny
65 2 gray rabbits
66 3 brown hares
67 4 black conies
68 END
69
70 cat >answer <<END # after cutting out cols 3-7, we get this
71 white
72 gray
73 brown
74 black
75 END
76
77 cut -c 3-7 x >y # extract columns 3-7
78 if cmp -s y answer; then : ; else echo Error in cut test 1; fi
79
80 #Test dd
81 dd if=$f of=x bs=12 count=1 2>/dev/null # x = bytes 0-11
82 dd if=$f of=y bs=6 count=4 skip=2 2>/dev/null # y = bytes 11-35
83 cat x y >z # z = bytes 0-35
84 dd if=$f of=answer bs=9 count=4 2>/dev/null # answer = bytes 0-35
85 if cmp -s z answer; then : ; else echo Error in dd test 1; fi
86
87 #Test df # hard to make a sensible Test here
88 rm ?
89 df >x
90 if test -r x; then : ; else echo Error in df Test 1; fi
91
92 #Test du # see df
93 rm ?
94 du >x
95 if test -r x; then : ; else echo Error in du Test 1; fi
96
97 #Test od
98 head -1 $f |od >x # see if od converts ascii to octal ok
99 if [ $ARCH = i86 -o $ARCH = i386 ]
100 then
101 cat >answer <<END
102 0000000 064124 020145 064564 062555 064040 071541 061440 066557
103 0000020 020145 064164 020145 060567 071154 071565 071440 064541
104 0000040 020144 067564 072040 066141 020153 063157 066440 067141
105 0000060 020171 064164 067151 071547 000012
106 0000071
107 END
108 else
109 cat >answer <<END
110 0000000 052150 062440 072151 066545 020150 060563 020143 067555
111 0000020 062440 072150 062440 073541 066162 072563 020163 060551
112 0000040 062040 072157 020164 060554 065440 067546 020155 060556
113 0000060 074440 072150 064556 063563 005000
114 0000071
115 END
116 fi
117
118 if cmp -s x answer; then : ; else echo Error in od test 1; fi
119
120 head -1 $f |od -d >x # see if od converts ascii to decimal ok
121 if [ $ARCH = i86 -o $ARCH = i386 ]
122 then
123 cat >answer <<END
124 0000000 26708 08293 26996 25965 26656 29537 25376 28015
125 0000020 08293 26740 08293 24951 29292 29557 29472 26977
126 0000040 08292 28532 29728 27745 08299 26223 27936 28257
127 0000060 08313 26740 28265 29543 00010
128 0000071
129 END
130 else
131 cat >answer <<END
132 0000000 21608 25888 29801 28005 08296 24947 08291 28525
133 0000020 25888 29800 25888 30561 27762 30067 08307 24937
134 0000040 25632 29807 08308 24940 27424 28518 08301 24942
135 0000060 31008 29800 26990 26483 02560
136 0000071
137 END
138 fi
139
140 if cmp -s x answer; then : ; else echo Error in od test 2; fi
141
142 #Test paste
143 cat >x <<END
144 red
145 green
146 blue
147 END
148
149 cat >y <<END
150 rood
151 groen
152 blauw
153 END
154 cat >answer <<END
155 red rood
156 green groen
157 blue blauw
158 END
159
160 paste x y >z
161 if cmp -s z answer; then : ; else echo Error in paste test 1; fi
162
163 #Test prep
164 echo >x <<END
165 "Hi," said Carol, laughing, "How's life?"
166 END
167
168 echo >answer <<END
169 hi
170 said
171 carol
172 laughing
173 how's
174 life
175 END
176
177 if cmp -s x answer; then : ; else echo Error in prep test 1; fi
178
179 #Test printenv
180 printenv >x
181 if grep HOME x >/dev/null; then : ; else echo Error in printenv test 1; fi
182 if grep PATH x >/dev/null; then : ; else echo Error in printenv test 2; fi
183 if grep SHELL x >/dev/null; then : ; else echo Error in printenv test 3; fi
184 if grep USER x >/dev/null; then : ; else echo Error in printenv test 4; fi
185
186 #Test pwd
187 pwd >Pwd_file
188 cd `pwd`
189 pwd >x
190 if test -s Pwd_file; then : ; else echo Error in pwd test 1; fi
191 if cmp -s Pwd_file x; then : ; else echo Error in pwd test 2; fi
192
193 #Test strings
194 #strings a.out | grep "MS-DOS" >x
195 #cat >answer <<END
196 #MS-DOS: Just say no
197 #END
198 #
199 #if cmp -s x answer; then : ; else echo Error in strings test 1; fi
200
201 #Test sum
202 sum $f >x
203 cat >answer <<END
204 29904 1
205 END
206
207 if cmp -s x answer; then : ; else echo Error in sum test 1; fi
208
209 #Test tee
210 cat $f | tee x >/dev/null
211 if cmp -s x $f; then : ; else echo Error in tee test 1; fi
212
213 #Test true
214 if true ; then : ; else echo Error in true test 1; fi
215
216 #Test uniq
217 cat >x <<END
218 100
219 200
220 200
221 300
222 END
223
224 cat >answer <<END
225 100
226 200
227 300
228 END
229
230 uniq <x >y
231 if cmp -s y answer; then : ; else echo Error in uniq test 1; fi
232
233 #Test pipelines
234 cat >x <<END
235 the big black dog
236 the little white cat
237 the big white sheep
238 the little black cat
239 END
240
241 cat >answer <<END
242 2 big
243 2 black
244 2 cat
245 1 dog
246 2 little
247 1 sheep
248 4 the
249 2 white
250 END
251
252 prep x | sort | uniq -c >y1
253 sort +1 <y1 >y
254 if cmp -s y answer; then : ; else echo Error in pipeline test 1; fi
255
256 cat $f $f $f | sort | uniq >x
257 sort <$f >y
258 if cmp -s x y; then : ; else echo Error in pipeline test 2; fi
259
260 cd ..
261 rm -rf DIR_SH2
262
263 echo ok
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.