[comp.unix.questions] AWK/ksh interaction question

lwv27@CAS.BITNET (08/04/90)

I am trying to parse a shell argument and pass the results down to an inline
awk script.  A sample of the code that I am trying to use is:
--- Cut Here ---
#! /bin/ksh
#       Assume 1 has -dx where x is a delimiter
#       and 2 as the file name to read

delim=$(echo FS=\"$(substr "$1" 2 1)\")
file="$2"

awk '
BEGIN   {
        '$delim'
        OFS=FS
        }

        {
        printf ("NR=%d; NF=%d; FS=.%s.; OFS=.%s.\n", NR, NF, FS, OFS)

        printf ("%s%s%s", $5, OFS, ORS)
        }
        ' $file
--- Cut Here ---

If I invoke this as:

tst1 -d: /etc/passwd

I get what I expect.  But, if I invoke this as:

ksh -x tst1 '-d ' /etc/passwd

awk claims that there is a syntax error.  What is strange is that if I
type in an awk script of:

--- Cut Here ---
awk '
BEGIN   {
        FS=" "
        OFS=FS
        }

        {
        printf ("NR=%d; NF=%d; FS=.%s.; OFS=.%s.\n", NR, NF, FS, OFS)

        printf ("%s%s%s", $5, OFS, ORS)
        }
        ' $file
--- Cut Here ---

then it seems to work just fine.  Same expansion.  Can anyone give me
a suggestion around this problem?

Thanks!
--
Larry W. Virden
Business: UUCP: osu-cis!chemabs!lwv27  INET: lwv27%cas.BITNET@CUNYVM.CUNY.Edu
Personal: 674 Falls Place,   Reynoldsburg,OH 43068-1614
Proline: lvirden@pro-tcc.cts.com   America Online: lvirden     CIS: [75046,606]