如何在bash中禁用编辑我的历史记录 [英] How to disable editing my history in bash

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

问题描述

在bash中,当我返回历史记录时,编辑一些命令并运行它,此编辑后的命令将附加到历史记录中,原始命令将保留完整.但是我偶尔会设法以某种方式影响原始命令,即我的编辑替换了历史记录中的原始命令.我不能指望这是怎么发生的.

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中设置了"vi"选项("set -o vi"-使用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,Del和字符键进行编辑时.

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

另一种模式是在您按Esc键时输入的"vi模式".

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. 当您按下Enter(执行),向上,向下或j,k(移动到历史记录中的另一个命令)时,更改将被应用.
  3. 如果您按Ctrl-C,则更改不会应用.
  4. 单独使用基本或vi风格的编辑不会影响历史记录中的原始命令.

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

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