RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1358372 - zsh command_not_found_handler should behave exactly the same way as its bash counterpart
Summary: zsh command_not_found_handler should behave exactly the same way as its bash ...
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: zsh
Version: 7.2
Hardware: All
OS: Linux
low
low
Target Milestone: rc
: ---
Assignee: Kamil Dudka
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-07-20 15:03 UTC by Tim Speetjens
Modified: 2020-08-13 08:31 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-07-21 08:58:17 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Knowledge Base (Solution) 2398991 0 None None None 2016-07-20 15:09:11 UTC

Description Tim Speetjens 2016-07-20 15:03:26 UTC
Description of problem:
The zsh command_not_found_handler has slighty different semantics, which make it less useful:
1 If the handler returns non-zero, the shell itself returns 127, regardless.
2 If the handler returns non-zero, the shell always prints an error message 'command not found', regardless.

This makes it impossible to differentiate an error with the handler (say, a user chose not to install the program with PackageKit), or an error code from the program. Also, this may print a command not found error, when the command actually launched.

In bash, this would be 0 if the handler installed the program, and it ran successfully, 127 if the handler didn't exist, or had an error, anything else, if the program exited with this error code.


Version-Release number of selected component (if applicable):
zsh-5.0.2

How reproducible:
100%


Steps to Reproduce / Actual results:
[user@host ~] $ zsh
[user@host] ~% not-found
zsh: command not found: not-found
[user@host] ~% echo $?
127
[user@host] ~% function command_not_found_handler() { return 0; }
[user@host] ~% not-found
[user@host] ~% echo $?
0
[user@host] ~% function command_not_found_handler() { return 3; }
[user@host] ~% not-found                                         
zsh: command not found: not-found
[user@host] ~% echo $?                                           
127
[user@host] ~% function command_not_found_handler() {
  echo "Command not found" >&2; return 127; }
[user@host] ~% not-found                                                                         
Command not found
zsh: command not found: not-found
[user@host] ~% echo $?                                                                           
127

Expected results:
[user@host ~] $ zsh
[user@host] ~% function command_not_found_handler() { return 0; }
[user@host] ~% not-found
[user@host] ~% echo $?
0
[user@host] ~% function command_not_found_handler() { return 3; }
[user@host] ~% not-found                                         
[user@host] ~% echo $?                                           
3
[user@host] ~% function command_not_found_handler() {
  echo "Command not found" >&2; return 127;
}
[user@host] ~% not-found                                                                       Command not found
[user@host] ~% echo $?                                                                           
127


Additional info:
For bash:

[user@host ~] $ unset command_not_found_handle
[user@host ~] $ not-found
bash: not-found: command not found
[user@host ~] $ echo $?
127
[user@host ~] $ function command_not_found_handle() { return 3; }
[user@host ~] $ not-found
[user@host ~] $ echo $?
3
[user@host ~] $ function command_not_found_handle() {
  echo "Command not found" >&2; return 127;
}
[user@host ~] $ not-found
Command not found
[user@host ~] $ echo $?
127

Comment 2 Kamil Dudka 2016-07-21 08:58:17 UTC
It works exactly as documented:

    If no external command is found but a function command_not_found_handler
    exists the shell executes this function with all command line arguments.
    The function should return status zero if it successfully handled the
    command, or non-zero status if it failed. In the latter case the standard
    handling is applied: `command not found' is printed to standard error and
    the shell exits with status 127. Note that the handler is executed in a
    subshell forked to execute an external command, hence changes to
    directories, shell parameters, etc. have no effect on the main shell.

This could be a topic for upstream discussion but we are not going to change the behavior during the life-time of RHEL-7 anyway.  From my point of view, there is no obvious benefit in passing the exit code out of PackageKit to an interactive shell session.

If your concern is about the error message being printed by zsh, I would suggest to just tweak the handler to always return zero if an action is taken.


Note You need to log in before you can comment on or make changes to this bug.