在bash编辑历史 [英] Editing history in bash

查看:143
本文介绍了在bash编辑历史的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在bash中,当我回到历史,编辑一些命令并运行它,这个编辑命令追加到历史和原来的保持不变。但每过一段时间我莫名其妙地设法影响原有的命令,即我的编辑取代了原来的命令回顾历史。我不能把我的手指上是如何发生的。有人能解释一下吗?我的目标是避免这种情况,所以任何编​​辑为previous命令总是被追加到历史,从来没有取代了原来的。

In bash, when I go back in history, edit some command and run it, this edited command is appended to history and the original one is left intact. But every once in a while I somehow manage to affect the original command, i.e. my edit replaces the original command back in history. I can't put my finger on how this happens. Can someone explain? My goal is to avoid this, so any edit to a previous command always gets appended to history and never replaces the original.

推荐答案

下面是我自己的答案,请更正或如果你能提供更多的细节。

Here's my own answer, please correct or provide more details if you can.

当六选项,在bash设置(设置-o六 - 使用vi风格的命令行编辑界面),有历史编辑命令两种模式

When the "vi" option is set in bash ("set -o vi" -- "Use a vi-style command line editing interface"), there are two modes of editing a command from history.

第一种模式(姑且称之为基础),是当你立即开始使用Backspace键,德尔和字符键编辑。

The first mode (let's call it "basic") is when you start editing immediately using Backspace, Del and character keys.

另一种模式是六模式,在输入时你打Esc键。

The other mode is the "vi mode", entered when you hit Esc.

如果你想保持你的历史完好无损,不要使用相同的编辑两种模式。我不知道的bash是怎么工作的,但你可以认为它是这样的:

If you want to keep your history intact, DO NOT use both modes in the same edit. I don't know how bash works exactly, but you can think of it this way:


  1. 进入vi模式适用于基本模式对原始命令的任何更改,并创建可以进一步编辑使用vi风格的命令该命令的副本。

  2. 当你打回车(执行),向上,向下或J,K(移动到历史上的另一个命令)的变化得到应用。

  3. 的变化没有得到,如果你按下Ctrl-C的应用。

  4. 使用基本或vi风格编辑ALONE不影响历史的原始命令。

这篇关于在bash编辑历史的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆