Score:0

How to briefly use last ignored (not saved in history file) command in bash?

au flag

In my bash config file .bashrc,I have set it up in a way that commands preceded by a space are not saved in history. What I am asking is, how to achieve similar function as this answer here which was used for zsh. I want to be able to access last command even though it is not stored in history.

vanadium avatar
cn flag
The answer you refer to is about *enabling* ignoring a command. It is not about accessing an ignored command. I do not think what you ask is possible: the command that was not stored in history = gone
llesh avatar
au flag
Maybe I need to redact my question. The thing is I want to access only the last command no matter if it has preceding spaces or not, just for the session. And if the command is preceded by space, next session it will not be shown.
Score:0
cn flag

Bash stores a command in history so you can retrieve it later. A command that is not stored in history, for example, because you preceded it with a space, or you deleted it later from the history with the history -d command, is gone from the history and cannot, by definition, be recalled. Not in bash, and not in zsh.

Of course, in terminal emulators, or if you use screen or tmux, you always can copy paste the command if it is still visible earlier in the buffer.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.