Skip to content

Commit cedf9a7

Browse files
committed
fix(awk): support backslash-newline line continuation
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
1 parent aa9255f commit cedf9a7

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

crates/bashkit/src/builtins/awk.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,10 @@ fn normalize_awk_newlines(input: &str) -> String {
433433
i += 1;
434434
}
435435
}
436+
'\\' if i + 1 < chars.len() && chars[i + 1] == '\n' => {
437+
// Backslash-newline: line continuation — join lines
438+
i += 2;
439+
}
436440
'\n' if brace_depth > 0 => {
437441
// Inside action block: replace newline with semicolon
438442
result.push(';');

crates/bashkit/tests/spec_cases/awk/awk.test.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,3 +703,24 @@ awk 'BEGIN{print "caf\u00E9"}'
703703
### expect
704704
café
705705
### end
706+
707+
### awk_backslash_newline_continuation
708+
# Issue #836: backslash-newline line continuation
709+
echo 'test' | awk '{
710+
x = 1 + \
711+
2
712+
print x
713+
}'
714+
### expect
715+
3
716+
### end
717+
718+
### awk_backslash_newline_condition
719+
# Issue #836: backslash-newline in condition
720+
echo '5' | awk '{
721+
if ($1 > 3 && \
722+
$1 < 10) print "yes"
723+
}'
724+
### expect
725+
yes
726+
### end

0 commit comments

Comments
 (0)