[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] syntax error when setting RS via string concatenation
From: |
arnold |
Subject: |
Re: [bug-gawk] syntax error when setting RS via string concatenation |
Date: |
Mon, 09 May 2016 07:41:36 -0600 |
User-agent: |
Heirloom mailx 12.4 7/29/08 |
Andy's got it.
Thanks,
Arnold
"Andrew J. Schorr" <address@hidden> wrote:
> 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