From b62fa53807a3154c8b596ffa42245e552cf62a23 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Fri, 17 Jan 2020 15:08:14 +0100 Subject: [PATCH] set error code on failed command substitution to 255 instead of -1 the exit status ought to be in 0-255, e.g. exit -1 --- src/exec.cpp | 7 ++++++- tests/checks/invocation.fish | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/exec.cpp b/src/exec.cpp index 0841c7fdd..0d509a64f 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -1157,7 +1157,12 @@ static int exec_subshell_internal(const wcstring &cmd, parser_t &parser, wcstrin // If the caller asked us to preserve the exit status, restore the old status. Otherwise set the // status of the subcommand. if (apply_exit_status) { - parser.set_last_statuses(subcommand_statuses); + // Hack: If the evaluation failed, avoid returning -1 to the user. + if (subcommand_statuses.status == -1) { + parser.set_last_statuses(statuses_t::just(255)); + } else { + parser.set_last_statuses(subcommand_statuses); + } } else { parser.set_last_statuses(std::move(prev_statuses)); } diff --git a/tests/checks/invocation.fish b/tests/checks/invocation.fish index d8ca460e5..89f41fb04 100644 --- a/tests/checks/invocation.fish +++ b/tests/checks/invocation.fish @@ -1,2 +1,8 @@ -#RUN: %fish -c "echo 1.2.3.4." +#RUN: %fish -C 'set -l fish %fish' %s + +$fish -c "echo 1.2.3.4." # CHECK: 1.2.3.4. + +PATH= $fish -c "echo (command a)" 2>/dev/null +echo $status +# CHECK: 255