Skip to content

fix(eval): empty eval string returns 0 - #1258

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/1013-eval-status
Oct 23, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/1013-eval-status

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #1013 (replaces #1193, closed unmerged). GNU builtins/evalstring.c:351 parse_and_execute inits last_result to EXECUTION_SUCCESS, so empty/blank/comment-only strings return 0 instead of preserving $?. Fix in execute_eval_source_inner + 3 regression tests. Tests: lib 712 + new file green; GNU parity byte-identical.

opencode and others added 2 commits October 23, 2026 14:14
…sult)

GNU builtins/eval.def:55 eval_builtin passes a non-null (even empty)
word list to evalstring; builtins/evalstring.c:351 parse_and_execute
initializes last_result = EXECUTION_SUCCESS and the :359 input loop
never runs for an empty string, so `eval ""` / `eval " "` /
comment-only strings return 0 instead of preserving $?.

Rubash routed Execute("") through execute_eval_source_inner where an
empty AST left exit_code untouched (rubash#1013: false; eval "" kept
1, and kept 127 after a 127 failure). Set exit_code = 0 when the
reparsed string yields zero commands, after redirect preparation so
`eval "" >f` keeps its truncation side effect.

Fixes #1013.
@caomengxuan666
caomengxuan666 merged commit 856abc6 into master Oct 23, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1013-eval-status branch October 23, 2026 08:54
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.

[bug] eval with no arguments preserves previous $? — GNU resets to 0

1 participant