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

@@ -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;
}