I'm aware that you can recall the last argument of the previous command with !$
and also cycle through previous arguments with ALT + .
but can you recall the last argument used for the current command that is being used?
e.g,
root@chip:/# echo peckahs
root@chip:/# *_stuffthatdoesntmatter_*
root@chip:/# *_stuffthatdoesntmatter_*
root@chip:/# *_stuffthatdoesntmatter_*
root@chip:/# echo peckahs < used key shortcut to recall 'peckahs' the last used argument for echo
Best Answer
With bash you can do nearly what you're asking for like this:
So when you do
the last line outputs
fun
.*
instead of$
produces all the arguments to the matching command; sooutputs
This is fun
again; but you might as well just doin this case.
This isn't limited to repeating a command's arguments with the same command:
See the bash reference manual for details. You could even combine this with the
histverify
shell option to give you a chance to check the command before it's executed, which gets you close to keyboard-interactive history-based completion.History expansions can be used anywhere; so for example
stored all the arguments to the last
echo
command in thelastechoargs
variable.This works for complete commands too; say for example you've worked out a complex
git
command, and you want to save it in a file:Or you want to archive some directories, but you decide to delete a couple of files first: