Repository navigation
fix(eval): empty eval string returns 0 - #1258
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.