Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For example, I edit and then run the same source.

vim arbit.py
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.

How can I do that?

share|improve this question
up vote 9 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.

share|improve this answer
    
With !:2 you reuse the second argument of the previous command. – Matthias Braun Sep 27 '14 at 4:28

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.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .