Skip to main content
added 3 characters in body
Source Link
user313992
user313992

You can't do that. Just like aliasesalias expansion, the command history expansion is performed when the function is defined, not when it's used.

You can access the history directly with the fc builtin, though:

$ redo(){ cmd=$(fc -nl -1 -1); echo "redoing '$cmd'"; eval "$cmd"; }
$ pwd
$ refo
redoing '      pwd'
/home2/ahq

You can't do that. Just like aliases expansion, the command history expansion is performed when the function is defined, not when it's used.

You can access the history directly with the fc builtin, though:

$ redo(){ cmd=$(fc -nl -1); echo "redoing '$cmd'"; eval "$cmd"; }
$ pwd
$ refo
redoing '      pwd'
/home2/ahq

You can't do that. Just like alias expansion, the command history expansion is performed when the function is defined, not when it's used.

You can access the history directly with the fc builtin, though:

$ redo(){ cmd=$(fc -nl -1 -1); echo "redoing '$cmd'"; eval "$cmd"; }
$ pwd
$ refo
redoing '      pwd'
/home2/ahq
Source Link
user313992
user313992

You can't do that. Just like aliases expansion, the command history expansion is performed when the function is defined, not when it's used.

You can access the history directly with the fc builtin, though:

$ redo(){ cmd=$(fc -nl -1); echo "redoing '$cmd'"; eval "$cmd"; }
$ pwd
$ refo
redoing '      pwd'
/home2/ahq