[comp.unix.shell] Am I using old-AWK or new-AWK?

brister@decwrl.dec.com (James Brister) (01/04/91)

Suppose I want to call AWK from a shell script, but I need the new version
of AWK.  Is there a little AWK script that will tell me what version I'm
using in a "decent" manner (i.e. doesn't just break if run under the old
version).

Thanks

James
--
James Brister                                           brister@decwrl.dec.com
DEC Western Software Lab., Palo Alto, CA    {uunet,sun,pyramid}!decwrl!brister

fitz@mml0.meche.rpi.edu (Brian Fitzgerald) (01/05/91)

In article <BRISTER.91Jan3162556@westworld.decwrl.dec.com> brister@decwrl.dec.com (James Brister) writes:
>Suppose I want to call AWK from a shell script, but I need the new version
>of AWK.  Is there a little AWK script that will tell me what version I'm
>using in a "decent" manner (i.e. doesn't just break if run under the old
>version).

If ARGC (argument count) is not predefined in your "old awk", try the
following:

#!/bin/sh
if awk 'BEGIN{ if (ARGC == 0 ) exit 0 ; exit 1 }'
then
    echo "Bad awk version" >&2
    exit 1
fi
... rest of shell script

Brian Fitzgerald