From f5083d7babfb124c53ba41dc55c7a81c073b06b1 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 27 Sep 2018 08:13:55 -0500 Subject: [PATCH] Set $status after `while` depending on whether loop was entered Closes #4982. --- CHANGELOG.md | 1 + src/parse_execution.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32cb43678..8ed15f048 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ fish 3.0 is a major release which brings with it both improvements in functional - Autosuggestions try to avoid arguments that are already present in the command line. - Variables may be used inside commands (#154). - A `hash` function has been added for compatibiility with `sh` and `bash` +- `while` sets `$status` to a more useful value (#4982) ## Other significant changes - Command substitution output is now limited to 10 MB by default (#3822). diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 48e70f271..f6e867a69 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -528,6 +528,7 @@ parse_execution_result_t parse_execution_context_t::run_while_statement( tnode_t condition_boolean_tail = header.child<3>(); // Run while the condition is true. + bool loop_executed = false; for (;;) { // Check the condition. parse_execution_result_t cond_ret = @@ -547,6 +548,8 @@ parse_execution_result_t parse_execution_context_t::run_while_statement( break; } + loop_executed = true; + // Push a while block and then check its cancellation reason. while_block_t *wb = parser->push_block(); this->run_job_list(contents, wb); @@ -569,6 +572,11 @@ parse_execution_result_t parse_execution_context_t::run_while_statement( break; } } + + if (loop_executed) { + proc_set_last_status(STATUS_CMD_OK); + } + return ret; }