I'm trying to create a function that will echo the previous to last command from the current terminal. This is the expected output (here I call the desired function f
):
$ history 1
history 1
$ f
history 1
Side question: Where does history(1)
saves the current terminal's history. I know that when the terminal session ends history is typically saved in $HISTFILE
(which is set to ~/.bash_history
in my case). But I'd like to know where history(1)
keeps the history of the currently running terminal.
!!:p
prints the last command without executing it. – schrodingerscatcuriosity Nov 22 '19 at 18:47fc -ln -1
(that’sFC -LN -(one)
, which works fine in a function. – G-Man Says 'Reinstate Monica' Nov 23 '19 at 03:03