bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subject: Pressing Ctrl-C during any subshell evaluation terminates t


From: Daniel Farina
Subject: Re: Subject: Pressing Ctrl-C during any subshell evaluation terminates the shell
Date: Mon, 12 Oct 2020 21:52:21 -0700

On Sun, Oct 11, 2020 at 12:59 PM Chet Ramey <chet.ramey@case.edu> wrote:
>
> On 10/9/20 7:23 PM, Daniel Farina wrote:
>
> > Bash Version: 5.0
> > Patch Level: 17
> > Release Status: release
> >
> > Description:
> >
> > Pressing Ctrl-C during any subshell evaluation terminates the shell.  I
> > noticed this when using direnv and emacs together: Ctrl-C would not cancel
> > a subprocess started by the shell, but would exit the entire shell.
> >
> > Relaying this from: https://github.com/direnv/direnv/issues/627
> >
> > Repeat-By:
> >
> > Per https://github.com/direnv/direnv/issues/627#issuecomment-635611930
> >
> > $ cat bash.rc
> > eval "$(direnv hook bash)"
>
> What commands does this `direnv' command output?

The source for it is at
https://github.com/direnv/direnv/blob/a4632773637ee1a6b08fa81043cacd24ea941489/shell_bash.go#L10-L20

And reads:

_direnv_hook() {
  local previous_exit_status=$?;
  trap -- '' SIGINT;
  eval "$("{{.SelfPath}}" export bash)";
  trap - SIGINT;
  return $previous_exit_status;
};
if ! [[ "${PROMPT_COMMAND:-}" =~ _direnv_hook ]]; then
  PROMPT_COMMAND="_direnv_hook${PROMPT_COMMAND:+;$PROMPT_COMMAND}"
fi

.selfPath is templated. This is embedded in a Go source file.

The version that does not exit looks like this. It is the version I use daily.

_direnv_hook() {
  local previous_exit_status=$?;
  eval "$("{{.SelfPath}}" export bash)";
  return $previous_exit_status;
};
if ! [[ "${PROMPT_COMMAND:-}" =~ _direnv_hook ]]; then
  PROMPT_COMMAND="_direnv_hook${PROMPT_COMMAND:+;$PROMPT_COMMAND}"
fi

https://github.com/direnv/direnv/blob/e2a7d51f31abf36d7983309a14f5036ea8aa6da2/shell_bash.go#L10-L17

> >
> > $ bash --rcfile bash.rc
> > bash$ echo $PROMPT_COMMAND
> > _direnv_hook
>
> What does `direnv_hook' do?
>
> > bash$ $(sleep 10) # pressing ^C during those 10 seconds will terminate the
> > shell
> > ^C
> > $ # inner shell terminated
>
> My guess is that it messes with the controlling terminal somehow, causing
> the shell to get EOF or -1/EIO when it attempts to read input.

direnv's purpose in life is to execute subshells that are then typed into.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]