Apply variable overrides for exec

Fixes #9995
This commit is contained in:
Fabian Boehm 2023-10-06 18:15:25 +02:00
parent 6775b0b1ad
commit 496d65fb5d
2 changed files with 11 additions and 2 deletions

View File

@ -1072,6 +1072,11 @@ bool exec_job(parser_t &parser, const shared_ptr<job_t> &j, const io_chain_t &bl
return false;
}
// Apply foo=bar variable assignments
for (const auto &assignment : j->processes.front()->variable_assignments) {
parser.vars().set(assignment.variable_name, ENV_LOCAL | ENV_EXPORT, assignment.values);
}
internal_exec(parser.vars(), j.get(), block_io);
// internal_exec only returns if it failed to set up redirections.
// In case of an successful exec, this code is not reached.

View File

@ -1,4 +1,5 @@
#RUN: %fish %s
#RUN: %fish -C 'set -l fish %fish' %s
exec cat <nosuchfile
#CHECKERR: warning: An error occurred while redirecting file 'nosuchfile'
#CHECKERR: warning: Path 'nosuchfile' does not exist
@ -10,7 +11,10 @@ not exec cat <nosuchfile
echo "neg failed: $status"
#CHECK: neg failed: 0
# See that variable overrides are applied to exec'd processes
$fish --no-config -c 'foo=bar exec env' | grep foo=bar
# CHECK: foo=bar
# This needs to be last, because it actually runs exec.
exec cat </dev/null
echo "not reached"