Skip to content

Commit d79f001

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 d951a45 commit d79f001

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
@@ -724,3 +724,24 @@ echo 'abc' | awk '/abc/ { print "yes" }'
724724
### expect
725725
yes
726726
### end
727+
728+
### awk_backslash_newline_continuation
729+
# Issue #836: backslash-newline line continuation
730+
echo 'test' | awk '{
731+
x = 1 + \
732+
2
733+
print x
734+
}'
735+
### expect
736+
3
737+
### end
738+
739+
### awk_backslash_newline_condition
740+
# Issue #836: backslash-newline in condition
741+
echo '5' | awk '{
742+
if ($1 > 3 && \
743+
$1 < 10) print "yes"
744+
}'
745+
### expect
746+
yes
747+
### end

0 commit comments

Comments
 (0)