Powershell: Practical use of $ ^ and $$?

I wonder who came up with some good options for the use of automatic variables $^, and $$in Powershell. At the moment, I do not see much benefit for them, at least from the point of view of the programmer.

When using PS in interactive mode and executing a long command, you can use .$^for repetition, and with help $$you can get the last argument, but .$^it looks pretty uncomfortable for me that I do not think this is something people will use every day. In addition, since it $$gives only the last argument, it is probably likewise difficult to use effectively.

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

+3
source share
1 answer

I use $$ constantly throughout my day. I use it little in scripts, but one operation that I usually do from the command line is to check the file and then open it in vim. $$ reduces keystrokes in this case.

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

Source: https://habr.com/ru/post/1707059/


All Articles