I use !$ multiple times every day but you just helped me make the connection to try !^ for the first argument and I think I'm going to start using that as well. Thanks!
At least in zsh, there are also !:1 for the first argument, et cetera with the rest of natural numbers, and something like !:* for all the arguments without the command.
The generic form is !n:m for n-th last command line and m-th argument, with an omitted n being a shortcut for the last line. Not sure if all of this works the same in bash.
And if you don't want the last argument but the nth one, press Alt-n before Alt-. (n starts at 0, so Alt-0 Alt-. in the above situation would get you "mkdir").
Comments (762) 128 threads
Show all comments
Showing thread 15 of 128
I would have referred to this using !$, which is one of the Bourne shell history substitutions. Like
(The "!" has the connotation "history" in the shell, while the "$" has the connotation "last", as in regular expressions.)An advantage of the way you mentioned is that you could actually see the history item displayed on the command line before running the command!
Another example could be
for "save the previous command into the file myscript".Continue this thread — 1 reply
The generic form is !n:m for n-th last command line and m-th argument, with an omitted n being a shortcut for the last line.
Not sure if all of this works the same in bash.
Continue this thread — 1 reply
https://www.man7.org/linux/man-pages/man3/readline.3.html
andAll engineers working with the command line (even after 35 years) really, really should open and read
to make sure you don't end up with something like urxvt-readline(1)
There are several other ways to do this sort of thing too. See e.g. https://stackoverflow.com/questions/4009412/how-to-use-argum...