Bash – Re-execute fc command from history

bashcommand history

Sometimes I am using the fc builtin in bash (3.2 if that matters), to recall commands from the history. This also offers the possibility to edit, before execution.

For example, by typing

fc 23 27

I can re-execute command 23 till 27. But now I want to execute this specific fc 23 27 command again. How should I do that? It looks as if the executed fc is not stored in the command history, although the newly executed lines are.

Best Answer

Add this to your .bashrc :

fc() {
    command fc "$@"
    history -s fc $@
}
Related Question