Bug 438841 - "fc -e 'edit' -1" edits wrong command
"fc -e 'edit' -1" edits wrong command
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: bash (Show other bugs)
All Linux
low Severity low
: rc
: ---
Assigned To: Roman Rakus
Ben Levenson
Depends On:
  Show dependency treegraph
Reported: 2008-03-25 11:38 EDT by john.haxby@oracle.com
Modified: 2014-01-12 19:07 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2009-01-20 16:10:27 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

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

  None (edit)
Description john.haxby@oracle.com 2008-03-25 11:38:34 EDT
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 11:38:34 EDT
Created attachment 299041 [details]
Proposed patch
Comment 2 RHEL Product and Program Management 2008-06-02 16:12:37 EDT
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
Comment 8 errata-xmlrpc 2009-01-20 16:10:27 EST
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.


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