If you want to re run a command with the same arguments you can do something like this:
vim long_filename
cat !$ #same as 'cat long_filename'
This saves having to type out the previous argument again when it is passed to cat.
However, how would I pass arguments that are not the same to the last run script/command?
long_annoying_script_name arg1 arg2
? arg3 arg4 #? signifies shortcut symbols such as '!$'
Of course I could just press the 'up' arrow and delete the arguments and type the new ones, but is there a shorter/faster way?
I DO NOT want to assign an alias.
!:0 should do the trick. From the zsh documentation:
Word Designators
A word designator indicates which word or words of a given command line
are to be included in a history reference. A `:' usually separates the
event specification from the word designator. It may be omitted only
if the word designator begins with a `^', `$', `*', `-' or `%'. Word
designators include:
0 The first input word (command).
n The nth argument.
^ The first argument. That is, 1.
$ The last argument.
% The word matched by (the most recent) ?str search.
x-y A range of words; x defaults to 0.
* All the arguments, or a null value if there are none.
x* Abbreviates `x-$'.
x- Like `x*' but omitting word $.
(It works with bash, too.) There’s also !-1 if you find that more convenient to type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With