bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with functions and the single quote in gawk


From: Aharon Robbins
Subject: Re: Problems with functions and the single quote in gawk
Date: Wed, 7 Mar 2001 09:53:57 +0200

Greetings.  Re this:

> From: Scollan, David 
> Sent: Monday, March 05, 2001 4:24 PM
> To:   'address@hidden'
> Subject:      address@hidden
> 
> # Try to print the contents of a file using a gawk function
> # This does not work. You need to put the code in an awk script and use
> nawk -f awk_script < $FILE
> # WHY?
> 
> FILE=$1
> gawk '{
>         function func1( param1 ){
>                 print param1
>                 return
>         }
>         func1( $0 )
> }' $FILE     

You have the syntax wrong.  The function should be defined outside the
braces.  Then call the function inside the braces:

        FILE=$1
        gawk ' function func1( param1 ){
                        print param1
                        return
                }

                { func1( $0 ) }' $FILE     


> Also, you can't put a ' in a comment but you can if you use gawk -f
> awk_script < $FILE as above  ie
> This script will fail WHY?
> gawk '{
>       print $0                # The single quote isn't allowed in this
> comment
> }' $FILE  

This is because of the shell's quoting rules.  The shell does not
do any processing of text inside single quotes.  As soon as it sees
the first single quote, it collects text up to the next one.

I hope this helps.

Arnold
--
Aharon (Arnold) Robbins --- Pioneer Consulting Ltd.     address@hidden
P.O. Box 354            Home Phone: +972  8 979-0381    Fax: +1 603 761-6761
Nof Ayalon              Cell Phone: +972 51  297-545    (See www.efax.com)
D.N. Shimshon 99785     Laundry increases exponentially in the
ISRAEL                  number of children. -- Miriam Robbins



reply via email to

[Prev in Thread] Current Thread [Next in Thread]