Skip to content

Implement e (execute) command - #481

Merged
dspinellis merged 12 commits into
uutils:mainfrom
PranavRJoshi:feat/e-comm
Aug 1, 2026
Merged

Implement e (execute) command#481
dspinellis merged 12 commits into
uutils:mainfrom
PranavRJoshi:feat/e-comm

Conversation

@PranavRJoshi

Copy link
Copy Markdown
Contributor

Fixes #476.

Implements the standalone e command (a GNU extension). Supports the command with and without arguments.

Changes:

  • Added the e command in compiler.rs/processor.rs, both forms (with argument, bare/pattern-space). Argument parsing reuses the same escape decoding and backslash continuation as a/c/i, as GNU sed's e argument follows the same syntax.
  • Rejected under --posix and --sandbox at compile time.
  • Fixed e and s///e to silently swallowing the child shell's stderr.
  • Added 17 tests covering both command forms, addressing, ';' not separating the argument, escape decoding, backslash continuation, --posix/--sandbox rejection, and stderr surfacing on failure.

Irrelevant: fixed a typo found at delimited_parser.rs.

Implement the 'e' command. No argument implies execution of pattern space and any respective argument is to run with the output written to stream. Rejected under --posix and --sandbox.

Also stop silently swallowing shell stderr for e and s///e.

Signed-off-by: PranavRJoshi <pranavrjoshi1@gmail.com>
Includes 17 new tests. Cover both forms of the new 'e' command: with-argument execution (including shell side effects, addressing, ';' not separating the argument, escape decoding, and backslash continuation) and the no-argument pattern-space form. Also cover --posix/--sandbox rejection and stderr surfacing on command failure.

Signed-off-by: PranavRJoshi <pranavrjoshi1@gmail.com>
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 2.40000% with 122 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.80%. Comparing base (e9792a8) to head (a3bc1ed).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/sed/compiler.rs 4.54% 63 Missing ⚠️
src/sed/processor.rs 0.00% 59 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #481      +/-   ##
==========================================
- Coverage   84.98%   83.80%   -1.19%     
==========================================
  Files          13       13              
  Lines        6760     6859      +99     
  Branches      378      388      +10     
==========================================
+ Hits         5745     5748       +3     
- Misses       1012     1108      +96     
  Partials        3        3              
Flag Coverage Δ
macos_latest 84.61% <2.47%> (-1.18%) ⬇️
ubuntu_latest 84.67% <2.47%> (-1.16%) ⬇️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PranavRJoshi

Copy link
Copy Markdown
Contributor Author

Seems like CRLF issue on Windows. Will make those tests conditionally compile on UNIX only.

@dspinellis dspinellis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the quick turnaround and thorough testing! I added a few improvement suggestions.

Comment thread src/sed/processor.rs Outdated
Comment thread src/sed/processor.rs Outdated
Comment thread src/sed/processor.rs Outdated
Comment thread src/sed/processor.rs Outdated
Comment thread src/sed/processor.rs Outdated
Comment thread src/sed/processor.rs Outdated
Comment thread src/sed/processor.rs Outdated
Comment thread tests/by-util/test_sed.rs
@PranavRJoshi

Copy link
Copy Markdown
Contributor Author

Appreciate the thorough review. Will make the appropriate changes and commit them later.

Validate shell output as utf-8 and error out instead of lossily converting it. Make CRLF strip conditionally compile to Windows only. Rename execute_pattern_as_shell to execute_pattern_as_shell_command. Add tests for non-utf-8 error paths.

Signed-off-by: PranavRJoshi <pranavrjoshi1@gmail.com>
Signed-off-by: PranavRJoshi <pranavrjoshi1@gmail.com>
Signed-off-by: PranavRJoshi <pranavrjoshi1@gmail.com>

@dspinellis dspinellis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some potential clashes with the highly relevant #487. Are you OK to delay the review a bit until we can land that so that we can ensure compatibility? In the meantime, please

  • try to address the drop in code coverage (I thought it would be addressed by your integration tests) , and
  • see why the GNU test suite results haven't changed. You can run the suite through util/run-gnu-testsuite.sh.

Reconcile the standalone e command with uutils#487's byte-oriented processing.

- Port compile_execute_command to build the command argument as bytes.
- Route s///e, bare e, and e-with-argument through one shared byte helper: shell_stdout.
- Keep shell output as raw bytes and drop UTF-8 validation so non-UTF-8 output passes through.
- Gate the CRLF strip to Windows only.

Signed-off-by: PranavRJoshi <pranavrjoshi1@gmail.com>
GNU sed applies the 'p' and 'e' substitution flags in the order they appear. 'pe' prints the pre-execution text then executes, while 'ep' executes then prints the result. Record whether 'p' precedes 'e' and apply them accordingly.

Signed-off-by: PranavRJoshi <pranavrjoshi1@gmail.com>
@github-actions

Copy link
Copy Markdown

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 65 / PASSED: 13 / FAILED: 42 / SKIPPED: 10
  Reference: TOTAL: 65 / PASSED: 12 / FAILED: 43 / SKIPPED: 10

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + eval

@PranavRJoshi

Copy link
Copy Markdown
Contributor Author

I went through the scripts exercising e/s///e. One of them, eval.sh, required strict flag ordering of p and e, which has been added. The other three that didn't pass was:

  • sandbox.sh: The rejection behavior is correct. But it fails on the format, i.e., our sed reports in the format <script argument N>:L:C: error: while GNU sed reports in the format -e expression #1, char N:.
  • posix-mode-s.sh: same format issue as well as unimplemented \l\L\U\u\E escapes. s///e execution passes.
  • execute-tests.sh: unimplemented W/T/F and big-number q. The e part passes.

@dspinellis dspinellis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All comments have been well-addressed and the changes have been rebased (thanks).

@dspinellis
dspinellis merged commit 84ae1b0 into uutils:main Aug 1, 2026
27 of 30 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.

Add e command (execute)

2 participants