Ido Shany
Ido Shany

Reputation: 79

Is there a way to take a previous argument?

I want to do this

mv <some path> <some path>/../

Is there a way to pass argv[1] as my argument and manipulate it, instead of writing the whole path again?

I.e.,

mv <some path> argv[1]/../

Upvotes: 1

Views: 83

Answers (2)

aioobe
aioobe

Reputation: 420971

In these situations, I usually use brace expansion:

mv <some path>{,/../}

which will expand to

mv <some path> <some path>/../

Example:

$ echo mv some/path{,/../other/path}
mv some/path some/path/../other/path

As @Pavlo Myroniuk points out in his answer, you can also follow the advice from here and do:

mv <some path> !#:1/../

Upvotes: 2

Pavlo Myroniuk
Pavlo Myroniuk

Reputation: 334

I've found the answer here. You can do it with:

mv file.txt !#:1.backup
  • !# - refers to the current command.
  • !#:1 - refers to the first argument of the current command

If you run this example you'll get:

mv file.txt file.txt.backup

Upvotes: 5

Related Questions