Using built-in commands and aliases
In this section, we'll review some useful commands built into PowerShell Core. These commands will work on any PowerShell Core installation and will increase the speed that we can operate on the command line.
Automatic Variable: $^ and $$
In PowerShell Core (and the older PowerShell 5), the automatic variables $^
and $$
always contain the first and last word of the previous command, respectively. PowerShell keeps this variable up to date as we issue commands. For example, let's create a new directory and then navigate into it using the $$
variable:
> cd ~/Desktop > mkdir SubDir > cd $$
Rather than retyping the name of the new directory, we can use the $$
variable. When executing the cd $$
command, the $$
variable represents the last word of the previous command, that is, SubDir
. This changes the directory to SubDir
.
Next, let's look at the $^
variable, which contains the first word of the previous command. We...