Skip to main content
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
Source Link

Why does bash change the history even I'm not executing a command I'm modifying? For example, if I type:

$ echo foo1 foo1 $ echo foo2 foo2 $ echo foo3 foo3 

After this, I press up twice, and I get echo foo2 on the prompt. I press 2 and get echo foo22. Now back to the end (empty line) with downdown. If I now search history, I'll see echo foo22 even though I've never executed that command!

However, when I exit the shell and open another one, I see the original, executed commands. I find all this very confusing, counter-intuitive and irritating.

I'd like the history thing to work like this:

  1. Only the commands actually executed are saved to the history.

  2. History is immutable. (Unless explicitly cleared.)

Is there a way to accomplish this?

Edit - this question seems related: Is there any way to undo a bash history modification?Is there any way to undo a bash history modification?

Why does bash change the history even I'm not executing a command I'm modifying? For example, if I type:

$ echo foo1 foo1 $ echo foo2 foo2 $ echo foo3 foo3 

After this, I press up twice, and I get echo foo2 on the prompt. I press 2 and get echo foo22. Now back to the end (empty line) with downdown. If I now search history, I'll see echo foo22 even though I've never executed that command!

However, when I exit the shell and open another one, I see the original, executed commands. I find all this very confusing, counter-intuitive and irritating.

I'd like the history thing to work like this:

  1. Only the commands actually executed are saved to the history.

  2. History is immutable. (Unless explicitly cleared.)

Is there a way to accomplish this?

Edit - this question seems related: Is there any way to undo a bash history modification?

Why does bash change the history even I'm not executing a command I'm modifying? For example, if I type:

$ echo foo1 foo1 $ echo foo2 foo2 $ echo foo3 foo3 

After this, I press up twice, and I get echo foo2 on the prompt. I press 2 and get echo foo22. Now back to the end (empty line) with downdown. If I now search history, I'll see echo foo22 even though I've never executed that command!

However, when I exit the shell and open another one, I see the original, executed commands. I find all this very confusing, counter-intuitive and irritating.

I'd like the history thing to work like this:

  1. Only the commands actually executed are saved to the history.

  2. History is immutable. (Unless explicitly cleared.)

Is there a way to accomplish this?

Edit - this question seems related: Is there any way to undo a bash history modification?

Tweeted twitter.com/StackUnix/status/774989142639902720
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k
Source Link
tuomassalo
  • 226
  • 1
  • 4

Why can I change bash history?

Why does bash change the history even I'm not executing a command I'm modifying? For example, if I type:

$ echo foo1 foo1 $ echo foo2 foo2 $ echo foo3 foo3 

After this, I press up twice, and I get echo foo2 on the prompt. I press 2 and get echo foo22. Now back to the end (empty line) with downdown. If I now search history, I'll see echo foo22 even though I've never executed that command!

However, when I exit the shell and open another one, I see the original, executed commands. I find all this very confusing, counter-intuitive and irritating.

I'd like the history thing to work like this:

  1. Only the commands actually executed are saved to the history.

  2. History is immutable. (Unless explicitly cleared.)

Is there a way to accomplish this?

Edit - this question seems related: Is there any way to undo a bash history modification?