mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-21 04:22:40 +08:00
Return a falsey status if the last -c
command has a parse error
This makes `fish -c begin` fail with a status of 127 - it already printed a syntax error so that was weird. (127 was the status for syntax errors when piping to fish, so we stay consistent with that) We allow multiple `-c` commands, and this will return the regular status if the last `-c` succeeded. This is fundamentally an extremely weird situation but this is the simple targeted fix - we did nothing, unsuccessfully, so we should fail. Things to consider in future: 1. Return something better than 127 - that's the status for "unknown command"! 2. Fail after a `-c` failed, potentially even checking all of them before executing the first? Fixes #9888
This commit is contained in:
parent
63b23713f2
commit
a6c36a014c
@ -262,6 +262,7 @@ static void read_init(parser_t &parser, const struct config_paths_t &paths) {
|
||||
|
||||
static int run_command_list(parser_t &parser, const std::vector<std::string> &cmds,
|
||||
const io_chain_t &io) {
|
||||
int retval = STATUS_CMD_OK;
|
||||
for (const auto &cmd : cmds) {
|
||||
wcstring cmd_wcs = str2wcstring(cmd);
|
||||
// Parse into an ast and detect errors.
|
||||
@ -276,14 +277,17 @@ static int run_command_list(parser_t &parser, const std::vector<std::string> &cm
|
||||
// Be careful to transfer ownership, this could be a very large string.
|
||||
auto ps = new_parsed_source_ref(cmd_wcs, *ast);
|
||||
parser.eval_parsed_source(*ps, io, {}, block_type_t::top);
|
||||
retval = STATUS_CMD_OK;
|
||||
} else {
|
||||
wcstring sb;
|
||||
parser.get_backtrace(cmd_wcs, *errors, sb);
|
||||
std::fwprintf(stderr, L"%ls", sb.c_str());
|
||||
// XXX: Why is this the return for "unknown command"?
|
||||
retval = STATUS_CMD_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// Parse the argument list, return the index of the first non-flag arguments.
|
||||
|
@ -572,24 +572,46 @@ $fish -c 'echo \utest'
|
||||
# CHECKERR: echo \utest
|
||||
# CHECKERR: ^~~~~^
|
||||
|
||||
echo $status
|
||||
# CHECK: 127
|
||||
|
||||
$fish -c 'echo \c'
|
||||
# CHECKERR: fish: Incomplete escape sequence '\c'
|
||||
# CHECKERR: echo \c
|
||||
# CHECKERR: ^^
|
||||
|
||||
echo $status
|
||||
# CHECK: 127
|
||||
|
||||
$fish -c 'echo \C'
|
||||
# CHECK: C
|
||||
echo $status
|
||||
# CHECK: 0
|
||||
|
||||
$fish -c 'echo \U'
|
||||
# CHECKERR: fish: Incomplete escape sequence '\U'
|
||||
# CHECKERR: echo \U
|
||||
# CHECKERR: ^^
|
||||
|
||||
echo $status
|
||||
# CHECK: 127
|
||||
|
||||
$fish -c 'echo \x'
|
||||
# CHECKERR: fish: Incomplete escape sequence '\x'
|
||||
# CHECKERR: echo \x
|
||||
# CHECKERR: ^^
|
||||
|
||||
echo $status
|
||||
# CHECK: 127
|
||||
|
||||
$fish -c begin
|
||||
# CHECKERR: fish: Missing end to balance this begin
|
||||
# CHECKERR: begin
|
||||
# CHECKERR: ^~~~^
|
||||
|
||||
echo $status
|
||||
# CHECK: 127
|
||||
|
||||
printf '%s\n' "#!/bin/sh" 'echo $0' > $tmpdir/argv0.sh
|
||||
chmod +x $tmpdir/argv0.sh
|
||||
cd $tmpdir
|
||||
|
Loading…
x
Reference in New Issue
Block a user