Comment 11 for bug 1479805

Revision history for this message
CarstenHey (c.hey) wrote : Re: [Bug 1479805] Re: /etc/bash_command_not_found is utterly broken

Hi,

Ubuntu's zsh c-n-f foo is fine now and c-n-f integration for bash is
done in the bash package, which is fine too (maybe this bash completion
c-n-f thing documented in the bash completion package could be added,
but I don't know how to trigger this specific bug which runs the c-n-f
magic in the bash completion - only how to prevent it).

* Steve Langasek [2016-06-17 14:57 -0000]:
> It doesn't appear to be true that this bug is currently in progress.
>
> However, I'm also not sure if there's anything further that needs doing
> for Ubuntu. The bzr history shows:
>
> committer: Michael Vogt <email address hidden>
> timestamp: Mon 2015-07-20 15:08:23 +0200
> message:
> merge /etc/zsh_command_not_found: from Carsten Hey
>
> But the timestamp on this is before the patch that was posted here.

Two different patches doing roughly the same were posted in different
ways ... I don't think that the reason is relevant, but I could explain
it if you really want to know.

> And the committed result is somewhat different than the one attached
> to this bug report.

Both patches are good, but not perfect (reaching perfection would be
quite tricky and the gain would be very small, for instance, a useless
stat(2) could be avoided).

I did not read the two patches now, anyway the later one contains very
very very minor improvements, either by catching some really weird
corner cases, or by being shorter, or by being more readable, or ... but
this is hardly a reason to invest any time in merging.

> Carsten, are any further changes needed to the zsh file?

No related changes are needed in Ubuntu.

> ** Changed in: command-not-found (Ubuntu)
> Status: In Progress => Incomplete
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1479805
>
> Title:
> /etc/bash_command_not_found is utterly broken
>
> Status in command-not-found package in Ubuntu:
> Incomplete
>
> Bug description:
> In a nutshell, if the package command-not-found is removed, but not
> purged, sourcing this file leads to silent failures if a command is
> not found.
>
> I don't use Ubuntu, but I assume that the file bash_command_not_found
> in the bzr repository is installed to /etc
>
> ./x is your bash_command_not_found with /usr/ replaced by /ur/ to
> simulate that the packages is removed but not purged.
>
> I use a self written printexitvalue (see tcsh and zsh), which prints
> the line "bash: exit $?" via $PROMPT_COMMAND - this is unrelated to
> the bug, but shown in the output below.
>
> $ unset -f command_not_found_handle
> $ cat x
> command_not_found_handle() {
> if [ -x /ur/lib/command-not-found ]; then
> /ur/lib/command-not-found -- "$1"
> return $?
> else
> return 127
> fi
> }
> $ foo
> bash: foo: command not found
> bash: exit 127
> $ . ./x
> $ foo
> bash: exit 127
> $
>
> As you can see, trying to run the non-available command foo results in
> no output (except of the one I do in $PROMPT_COMMAND) and correctly
> fails with exit code 127. It does not print "bash: foo: command not
> found", as it should.
>
> command_not_found_handle() is not command_not_found_handler() (note
> the trailing 'r' in the word handler, that's not in the word handle).
> man bash (for the former function) and man zshall (for the latter
> function) contain the glory details how both functions work and how
> they differ. If /usr/lib/command-not-found is available, your
> command_not_found_handle() implementation behaves as it should, but if
> /usr/lib/command-not-found is not available it behaves as zsh's
> command_not_found_handler() should, but not as a
> command_not_found_handle() should.
>
> An untested, but presumably correct implementation, except of the
> unconditional overwriting of the function (I don't know how to prevent
> this in bash properly), and returning 127 when it should return 126
> (see man p exec), based on /etc/zsh_command_not_found, is shown below.
>
> Please replace two leading spaces with a tab, four leading spaces with
> two tabs and so on; and don't replace "|| return $?" with "\nreturn
> $?", in case someone uses set -e interactively. I quoted the words
> return and builtin to guard against weird alias definitions (I did not
> do this in the zsh snipppet because, in general, I expect zsh users to
> have at least basic shell knowledge, and sometimes zsh users do ugly
> things on purpose.
>
>
> # (c) Zygmunt Krynicki 2007,
> # Licensed under GPL, see COPYING for the whole text
> #
> # This script will look-up command in the database and suggest
> # installation of packages available from the repository
>
> if [[ -x /usr/lib/command-not-found ]] ; then
> command_not_found_handle() {
> [[ -x /usr/lib/command-not-found ]] || {
> \builtin printf >&2 'bash: %scommand not found\n' ${1+"$1: "}
> \return 127
> }
> /usr/lib/command-not-found -- ${1+"$1"} || \return $?
> }
> fi
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/command-not-found/+bug/1479805/+subscriptions