Skip to content

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

Closed
caomengxuan666 wants to merge 1 commit into
masterfrom
fix/1013-eval-status
Closed

caomengxuan666 wants to merge 1 commit into
masterfrom
fix/1013-eval-status

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #1013. 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: zero-command AST sets exit 0 after redirect setup (unevaluated redirects like eval "" >f still truncate, GNU rc 0). Tests: lib 712 + related suites green; GNU parity (empty/blank/comment/bare/valid) byte-identical.

…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 deleted the fix/1013-eval-status branch October 23, 2026 04:53
@caomengxuan666
caomengxuan666 restored the fix/1013-eval-status branch October 23, 2026 06:14
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