Skip to content

fix(builtins): count newlines for wc -l instead of logical lines#481

Merged
chaliy merged 1 commit intomainfrom
claude/fix-401-Y2nIj
Mar 2, 2026
Merged

fix(builtins): count newlines for wc -l instead of logical lines#481
chaliy merged 1 commit intomainfrom
claude/fix-401-Y2nIj

Conversation

@chaliy
Copy link
Contributor

@chaliy chaliy commented Mar 2, 2026

Summary

  • Fixed wc -l to count \n characters instead of using Rust's .lines().count(), matching real bash behavior
  • printf "a\nb\nc" now correctly returns 2 (two newlines) instead of 3 (three logical lines)
  • Added tests for wc -l in pipe contexts

Closes #401

Test plan

  • test_wc_l_in_pipe
  • test_wc_l_in_pipe_subst
  • test_wc_l_counts_newlines
  • All existing wc tests pass

Real bash wc -l counts \n characters, not logical lines. This means
text without a trailing newline reports one fewer line. Changed from
text.lines().count() to counting \n characters directly.

Closes #401
@chaliy chaliy merged commit 183eaa2 into main Mar 2, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(builtins): wc -l in pipe returns -1

2 participants