xref: /illumos-gate/usr/src/test/util-tests/tests/awk/gnu/messages.sh (revision 8a2b682e57a046b828f37bcde1776f131ef4629f)
1#!/bin/bash
2
3if [[ -z "$AWK" || -z "$WORKDIR" ]]; then
4    printf '$AWK and $WORKDIR must be set\n' >&2
5    exit 1
6fi
7
8TEMP1=$WORKDIR/test.temp.1
9TEMP2=$WORKDIR/test.temp.2
10TEMP3=$WORKDIR/test.temp.3
11
12# This is a demo of different ways of printing with gawk.  Try it
13# with and without -c (compatibility) flag, redirecting output
14# from gawk to a file or not.  Some results can be quite unexpected.
15$AWK 'BEGIN {
16	print "Goes to a file out1" > "'$TEMP1'"
17	print "Normal print statement"
18	print "This printed on stdout" > "/dev/stdout"
19	print "You blew it!" > "/dev/stderr"
20}' > $TEMP2 2> $TEMP3
21
22diff out1.ok $TEMP1 \
23    && diff out2.ok $TEMP2 \
24    && diff out3.ok $TEMP3 \
25    && rm -f $TEMP1 $TEMP2 $TEMP3
26