Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

i wonder why this isn't default bash history behavior? Wouldn't it be way more useful this way?


sort by: page size:

Thank you!! Why on earth isn't that the default. It always seemed weird that with multiple bash windows open, the commands from most of them weren't added to the history.

And bash lets you accidentally screw up the history, because it's editable by default, and just weird ^p/^n behaviour

Just tested it and 'history -a' behaves how you say. Maybe it was an older version of bash that had this behavior.

Edit: now I'm obsessing about reproducing this behavior from years ago! If anyone knows what I'm talking about I'd be grateful for some validation :)


I thought that the command history search was default behavior for BASH? (I use zsh)

I do the same, except instead of `history` i grep the .bash_history file :-P

(i almost always need it for stuff i typed several sessions ago)


Interesting I didn't know that in screen you could isolate bash history per context.

Heh. This is funny timing, as .bash_history made me feel like an idiot just yesterday morning.

I was sitting here between queries and I thought 'y'know, all I ever do with history is grep for things. I wonder what else I can do?' When I want to learn about something quick, I usually start with the built-in help; so I did

history --help

The built-in help for history, unfortunately, is woefully inadequate; this was the output:

history: usage: history [-c] [-d offset] [n] or history -awrn [filename] or history -ps arg [arg...]

I said to myself: "Hmm. Wonder what those do?" -- and in a moment of bash stupidity, I thought: "well, let's try it!"

history -c

There's no output from that command, but it didn't take long to figure out what it does. It deletes your entire bash history, clearing the history in RAM and emptying .bash_history.

Since I use history all the time, I panicked. Holy crap! What have I done? I spent a few minutes internalizing the obvious lesson that everybody knows - never run commands without knowing them first. Thankfully, though, I had another bash open at the time. And after I'd beaten myself up over it, I thought for a moment, jumped over to the other shell, and did:

cd && history | cut -c 8- >> .bash_history

... because (after all) the evil, evil history -c command doesn't kill the history from RAM in other shells.

Lucky me.


I understand your comment. Intuitively I agree with you but in the context of one of the original devs writing bash it would make no sense to tie the history command to the interactive REPL. Treating everything the same would lead to less bugs in "their" system while leaving a caveat for all the userland script writers.

I couldn't really find a good reason to use a .bash_history. I linked mine to /dev/null and never looked back. (heh)

Why even store your bash history? It's like you store everything you ever said... Would you lose your precious time to go through the old stuff? I wouldn't.

I have a little bit of bash to save my history files and a custom search, hss, to search across them. This makes the exposure an order of degrees, if it's in bash history already then it's going to hang around longer. If I weren't doing this if still have the same problem with bash's built-in/default history.

I started this in response to a HN post some years ago.


Thanks for the link! I've been looking for a writeup on bash history features for a while. These things are very useful day-to-day.

Just fix bash so it saves every line of your history ever, no exceptions and no deletions. (Except for the 'leading space' trick when security considerations are in play.)

It's insane that this isn't the default behavior and can't even be configured in 2021!


Thanks, I didn’t know that! I use the fish shell, which does history searching differently but this is useful for those few times when I’m in bash.

It would be nice if it could look through .bash_history when it's first run, or something.

I'm totally fine with bash if it could share history between processes by default. That's pain when I operate in someone's server.

Easy answer. It's a built in history.

I use bash history all the time, I use my browser history all the time.

To be able to use an OS history would be amazing.

What was the name of the esoteric software i was using to program my lego robot,

What was I working on last Thursday so I can fill out the government required SHRED report to get the Canadian RnD tax rebate.

What was the song i was listening to that Spotify played last Tuesday afternoon.

There are so many times i'd use a feature like this.


I maintain almost all my bash history and I often use it to reconstruct a sequence of events in the past when I feel like maybe a mistake had been made.

I wish I had bash history that long. Never seems to have the command I want when I look for it.
next

Legal | privacy