/etc/bash_command_not_found is utterly broken
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
command-not-found (Ubuntu) |
Fix Released
|
Low
|
Zygmunt Krynicki |
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_
./x is your bash_command_
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_
$ cat x
command_
if [ -x /ur/lib/
/ur/
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_
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_
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_
[[ -x /usr/lib/
\builtin printf >&2 'bash: %scommand not found\n' ${1+"$1: "}
\return 127
}
/usr/
}
fi
Related branches
- CarstenHey (community): Approve
- Command Not Found Developers: Pending requested
-
Diff: 46 lines (+18/-12)2 files modifiedbash_command_not_found (+11/-8)
zsh_command_not_found (+7/-4)
Changed in command-not-found (Ubuntu): | |
importance: | Undecided → Medium |
Changed in command-not-found (Ubuntu): | |
importance: | Medium → Low |
Changed in command-not-found (Ubuntu): | |
assignee: | nobody → Zygmunt Krynicki (zyga) |
A possible changelog entry is:
* /etc/bash_ command_ not_found: print error message if a command
is not found, and the package has been removed but not purged.
I think an indentation with four spaces is better for this file (in order to avoid line wrapping on 80x25 terminals).
This file is indented accordingly and I have replaced ']] ;' with ']];', since, unlike the zsh variant, it contains no ')) ;' :
http:// stateful. de/~carsten/ tmp/150730QuR6x wuv7Z0/ bash_command_ not_found
Testing the function, i.e., w/o the “if [[ -x /usr/lib/ command- not-found ]] ; then” guard around the function definition, before committing seems to be a good idea. This requires an Ubuntu installation (which I do not have) and should be done with the package installed, and with the package removed but not purged.
Btw., \builtin print avoids functions and aliases named printf, which could lead to a command- not-found- error in command_ not_found_ handle( ) - not in a bulletproof way, but for this we'd need a new POSIX release.