bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] syntax error when setting RS via string concatenation


From: Andrew J. Schorr
Subject: Re: [bug-gawk] syntax error when setting RS via string concatenation
Date: Mon, 9 May 2016 09:32:01 -0400
User-agent: Mutt/1.5.23 (2014-03-12)

On Mon, May 09, 2016 at 08:16:17AM -0500, Ed Morton wrote:
> I didn't expect to get this syntax error when setting RS via string 
> concatenation:
> 
>     $ awk 'BEGIN{RS="[x"; RS=RS"]"}'
>     awk: cmd. line:1: fatal: Unmatched [, [^, [:, [., or [=: /[x/
> 
> as opposed to setting it to a variable constructed by the same string 
> concatenation
> 
>     $ awk 'BEGIN{t="[x"; t=t"]"; RS=t}'
>     $
> 
> Is that a bug or a feature (and if so, what feature?).

I think it's a feature. Consider this:

bash-4.2$ ./gawk 'BEGIN {RS = "[x"}'
gawk: cmd. line:1: fatal: Unmatched [, [^, [:, [., or [=: /[x/

Why should setting RS to an invalid regexp succeed? There is no way for gawk to
know that it should ignore RS because you plan to fix it later.

Your workaround using a temporary variable seems to be the
correct solution.

Regards,
Andy



reply via email to

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