The Computer Oracle

How can I run a different command but with the same arguments?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Over a Mysterious Island

--

Chapters
00:00 How Can I Run A Different Command But With The Same Arguments?
00:22 Accepted Answer Score 14
01:00 Answer 2 Score 3
01:26 Thank you

--

Full question
https://superuser.com/questions/248029/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #commandline #bash #unix

#avk47



ACCEPTED ANSWER

Score 14


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.




ANSWER 2

Score 3


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.