[Bug 841221] Re: In zsh command not found triggers upon any subshell exit code != 0

CarstenHey carsten at debian.org
Thu Jul 30 11:20:58 UTC 2015


This bug is fixed in recent Ubuntu releases by using
command_not_found_handler() and might be closed.

Anyway, I need a place to dump old useless code I presumably never need
again (in case I'm wrong and I'll find a use case for this) ...


Actually, according to the POSIX standard and zsh's implementation, exec returns 127 it the command is not found at all. and 126 if a file matching the command's name w/o executable bit set if found in $PATH, therefore the correct fix for this issue would be (if it wouldn't have been fixed by using command_not_found_handler already), to check if $? is 126 or 127.

An untested example fix (that also fixes other things), based on the
version still in Debian, is pasted below (warning: the sequence >&-
should not be used for anything except shell builtins or commands you
wrote yourself):


[[ -x /usr/share/command-not-found/command-not-found ]] || return 0

function cnf_preexec() {
  typeset -g cnf_command="${1%% *}"
}

function cnf_precmd() {
  case $? in (126|127)
    if [[ -n "${cnf_command-}" && -x /usr/share/command-not-found/command-not-found ]]
    then
      whence -- "$cnf_command" >&- ||
          /usr/bin/python /usr/share/command-not-found/command-not-found -- "$cnf_command"
      unset cnf_command
    fi
    ;;
  esac
}

typeset -ga preexec_functions
typeset -ga precmd_functions
preexec_functions+=cnf_preexec
precmd_functions+=cnf_precmd

** Changed in: command-not-found (Ubuntu)
       Status: New => Fix Released

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to command-not-found in Ubuntu.
https://bugs.launchpad.net/bugs/841221

Title:
  In zsh command not found triggers upon any subshell exit code != 0

Status in command-not-found package in Ubuntu:
  Fix Released

Bug description:
  This bug is present in at least two versions : Ubuntu 10.04.3 LTS and
  Ubuntu 11.04.

  command-not-found package version is 0.2.40ubuntu5 on the 10.04 system
  and 0.2.41ubuntu2 on the other.

  In zsh, when running commands in a subshell (and in other occasions,
  such as running a python script), if the return code from the subshell
  is non-zero, the command-not-found handler triggers, when it should
  not.

  Example : Running the "true" command in a subshell works correctly.

  > (true)

  Example : Running the "false" command in a subshell triggers command-
  not-found, but expected nothing to happen.

  > (false)
  (false) : commande introuvable

  The fix is easy : in /etc/zsh_command_not_found, change the line
  "(($?)) && …" to "(($? == 127)) && …".

  Hope this helps improve this useful tool.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/command-not-found/+bug/841221/+subscriptions



More information about the foundations-bugs mailing list