Set $status after while depending on whether loop was entered

Closes #4982.
This commit is contained in:
Mahmoud Al-Qudsi 2018-09-27 08:13:55 -05:00
parent 8ff0e7441f
commit f5083d7bab
2 changed files with 9 additions and 0 deletions

View file

@ -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).

View file

@ -528,6 +528,7 @@ parse_execution_result_t parse_execution_context_t::run_while_statement(
tnode_t<g::andor_job_list> 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<while_block_t>();
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;
}