From d79f0018d8b0367d388ab4e4243b31b43869f7f0 Mon Sep 17 00:00:00 2001 From: Mykhailo Chalyi Date: Thu, 26 Mar 2026 17:14:27 +0000 Subject: [PATCH] fix(awk): support backslash-newline line continuation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backslash immediately before a newline is now treated as line continuation in awk programs — the two characters are removed and the physical lines are joined. This is standard POSIX awk behavior. Closes #836 --- crates/bashkit/src/builtins/awk.rs | 4 ++++ .../bashkit/tests/spec_cases/awk/awk.test.sh | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/crates/bashkit/src/builtins/awk.rs b/crates/bashkit/src/builtins/awk.rs index f3b08678..30f895b4 100644 --- a/crates/bashkit/src/builtins/awk.rs +++ b/crates/bashkit/src/builtins/awk.rs @@ -433,6 +433,10 @@ fn normalize_awk_newlines(input: &str) -> String { i += 1; } } + '\\' if i + 1 < chars.len() && chars[i + 1] == '\n' => { + // Backslash-newline: line continuation — join lines + i += 2; + } '\n' if brace_depth > 0 => { // Inside action block: replace newline with semicolon result.push(';'); diff --git a/crates/bashkit/tests/spec_cases/awk/awk.test.sh b/crates/bashkit/tests/spec_cases/awk/awk.test.sh index b71fe95d..19cd23c0 100644 --- a/crates/bashkit/tests/spec_cases/awk/awk.test.sh +++ b/crates/bashkit/tests/spec_cases/awk/awk.test.sh @@ -724,3 +724,24 @@ echo 'abc' | awk '/abc/ { print "yes" }' ### expect yes ### end + +### awk_backslash_newline_continuation +# Issue #836: backslash-newline line continuation +echo 'test' | awk '{ + x = 1 + \ + 2 + print x +}' +### expect +3 +### end + +### awk_backslash_newline_condition +# Issue #836: backslash-newline in condition +echo '5' | awk '{ + if ($1 > 3 && \ + $1 < 10) print "yes" +}' +### expect +yes +### end