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