Skip to content

bug: awk parser doesn't treat newlines as statement separators between assignments #809

@chaliy

Description

@chaliy

Problem

The awk parser does not recognize newlines as statement terminators when the next statement is an assignment. Two consecutive assignments separated by a newline (no semicolons) cause an "invalid assignment target" error.

Reproduction

echo test > /tmp/t.txt
awk '
{
    x=1
    y=2
    print x, y
}
' /tmp/t.txt

Real awk: prints 1 2
Bashkit: awk: invalid assignment target

Adding semicolons fixes it:

awk '{ x=1; y=2; print x, y }' /tmp/t.txt  # works

Root cause

The awk parser likely treats the newline between x=1 and y=2 as implicit concatenation rather than a statement separator. It interprets:

x = 1
y = 2

as something like x = (1 y) = 2, which produces "invalid assignment target" because (1 y) is not a valid lvalue.

Per the POSIX awk spec, newlines are statement terminators equivalent to semicolons inside action blocks and function bodies.

Patterns that work vs fail

# FAIL: two assignments on separate lines
{ x=1
  y=2 }

# OK: semicolons
{ x=1; y=2 }

# OK: assignment followed by print  
{ x=1
  print x }

# OK: two if-statements
{ if (1) print "a"
  if (1) print "b" }

# FAIL: assignment after if (if last stmt is assignment-like)
{ if (1) x=1
  y=2 }

Impact

Critical. Nearly all multi-line awk programs use newline-separated assignments. This blocks the entire wedow/ticket script's awk processing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions