I am sure I have seen this somewhere, but I can't find it again :(

For example, I edit and then run the same source. vim arbit.py and then python arbit.py. I know I could run it from within vim, but I want a general solution on bash. I keep finding situations where I reuse arguments.

I can haz any tipz?

link|improve this question
feedback

2 Answers

up vote 3 down vote accepted

Use $*. It expands to all words except the first one (i.e. the command).

$ vim arbit.py
$ python !*
python arbit.py

You can combine it with all the features of !, for example:

$ vim arbit.py
$ ls
$ python !vim:*
vim arbit.py

Or, if you want only the last word, there are two other ways:

$ vim arbit.py
$ python !$

or:

$ vim arbit.py
$ python <Esc+.>

See the bash history interaction documentation for more details.

link|improve this answer
thanks for link and the solution! – Sanjeev Satheesh Feb 20 '11 at 7:02
wow! thanks a lot! – max taldykin Feb 21 '11 at 7:21
feedback

There are at least a couple of ways to do this.

$ vim arbit.py
$ python[press Alt-.]

which retrieves the last argument of the previous command as does:

$ vim arbit.py
$ python !$

or

$ vim arbit.py
$ python !*

which retrieves all the arguments of the previous command.

link|improve this answer
thanks for the solutions – Sanjeev Satheesh Feb 20 '11 at 7:05
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.