Bug 438841 - "fc -e 'edit' -1" edits wrong command
Summary: "fc -e 'edit' -1" edits wrong command
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: bash
Version: 5.1
Hardware: All
OS: Linux
low
low
Target Milestone: rc
: ---
Assignee: Roman Rakus
QA Contact: Ben Levenson
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2008-03-25 15:38 UTC by john.haxby@oracle.com
Modified: 2014-01-13 00:07 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2009-01-20 21:10:27 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Proposed patch (1000 bytes, patch)
2008-03-25 15:38 UTC, john.haxby@oracle.com
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2009:0116 0 normal SHIPPED_LIVE bash bug fix update 2009-01-20 16:04:47 UTC

Description john.haxby@oracle.com 2008-03-25 15:38:34 UTC
Description of problem:

"fc -e echo" and "fc -e echo -1" should simply run the last command, but the
latter runs the last-but-one command.  Even worse,"fc -e echo xxx" reports
"bash: fc: history specification out of range" when "xxx" is the last command
run (provided that there is no other "xxx" in the history.



Version-Release number of selected component (if applicable): bash-3.1-16.1.x86_64


How reproducible: always


Steps to Reproduce:
1. run three commands, "aaa", "bbb", "ccc" (it doesn't matter that these aren't
found, in fact it's safer if they're not).
2. "fc -e cat -1" should re-run the last command, ccc
3. Similarly, "fc -e cat ccc" should also re-run ccc (after re-priming the history).
  
Actual results:
(2) re-runs bbb instead of ccc
(3) reports a history range out of range error


Expected results:
In both cases, ccc should be re-run


Additional info:


This bug has been around for a while and it finally annoyed me enough to track
it down.  I have a small shell function that runs the last command with "sudo"
in front of it, viz:

    please () {
        fc -e 'sed -i "s/^/sudo /"' -1
    }

I discovered in the course of investigating this that missing off the "-1"
results in a working function.

The attached patch (which can also be found at
http://lists.gnu.org/archive/html/bug-bash/2008-03/msg00035.html) fixes the
problem by the call to delete_last_history() _after_ the block that calculates
histbeg and histend.  The default cases (where the history number is not
specified) are unaffected by this move.

This bug has been around for quite some time, probably since this change:

q.  The `fc' builtin now removes the `fc' command that caused it to invoke an
    editor on specified history entries from the history entirely, rather than
    simply ignoring it.

Comment 1 john.haxby@oracle.com 2008-03-25 15:38:34 UTC
Created attachment 299041 [details]
Proposed patch

Comment 2 RHEL Program Management 2008-06-02 20:12:37 UTC
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux maintenance release.  Product Management has requested
further review of this request by Red Hat Engineering, for potential
inclusion in a Red Hat Enterprise Linux Update release for currently deployed
products.  This request is not yet committed for inclusion in an Update
release.

Comment 8 errata-xmlrpc 2009-01-20 21:10:27 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2009-0116.html


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