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