Joey
Joey

Reputation: 354536

Powershell: Practical usage of $^ and $$?

I am wondering whether anyone came up with good use cases of the $^ and $$ automatic variables in Powershell. At the moment I am not seeing much use for them, at least from a programmer perspective.

When using PS interactively and executing a long command you could use .$^ to repeat it and with $$ you could get the last argument, but .$^ looks awkward enough to me that I don't consider that something people would use every day. Furthermore, since $$ only yields the last argument it's probably similarly difficult to use effectively.

But maybe I'm just mistaken and they have useful uses and I just can't see them.

Upvotes: 3

Views: 540

Answers (1)

JaredPar
JaredPar

Reputation: 754735

I use the $$ constantly during my day. I find little use for it in scripts but one operation I commonly do from the command line is to checkout a file and then open it in vim. The $$ reduces keystrokes in that circumstance.

PS> tf edit some\Long\Path\To\This\File\I\Need\To\Edit.cpp
Edit.cpp checked out
PS> gvim $$

Upvotes: 9

Related Questions