xref: /illumos-gate/usr/src/test/util-tests/tests/awk/tests/T.main (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
1#!/bin/bash
2
3if [[ -z "$AWK" ]]; then
4    printf '$AWK and $WORKDIR must be set\n' >&2
5    exit 1
6fi
7
8TEMP0=$WORKDIR/test.temp.0
9TEMP1=$WORKDIR/test.temp.1
10TEMP2=$WORKDIR/test.temp.2
11
12RESULT=0
13
14fail() {
15	echo "$1" >&2
16	RESULT=1
17}
18
19echo T.main: misc tests of arguments in main
20
21rm -f core
22
23# test -d option
24
25
26
27echo hello | $AWK -d '{print}' > $TEMP1
28if [[ $? -eq 139 ]]; then fail "BAD: T.main awk -d dropped core"; fi
29
30echo 'a::b::c' > $TEMP0
31$AWK -F:: '{print NF}' $TEMP0 > $TEMP1
32echo '3' > $TEMP2
33diff $TEMP1 $TEMP2 || fail 'bad: awk -F::'
34
35echo 'a::b::c' > $TEMP0
36$AWK -F :: '{print NF}' $TEMP0 > $TEMP1
37echo '3' > $TEMP2
38diff $TEMP1 $TEMP2 || fail 'bad: awk -F ::'
39
40echo 'a	b	c' > $TEMP0
41$AWK -F t '{print NF}' $TEMP0 > $TEMP1
42echo '3' > $TEMP2
43diff $TEMP1 $TEMP2 || fail 'bad: awk -F (tab)'
44
45echo 'a	b	c' > $TEMP0
46$AWK -Ft '{print NF}' $TEMP0 > $TEMP1
47echo '3' > $TEMP2
48diff $TEMP1 $TEMP2 || fail 'bad: awk -F (tab 2)'
49
50echo 'atabbtabc' > $TEMP0
51$AWK -F tab '{print NF}' $TEMP0 > $TEMP1
52echo '3' > $TEMP2
53diff $TEMP1 $TEMP2 || fail 'bad: awk -F tab'
54
55exit $RESULT
56