As far as I can see using $pwd
and using ./
in PowerShell gives the same result.
Are they the same or is there a difference?
As far as I can see using $pwd
and using ./
in PowerShell gives the same result.
Are they the same or is there a difference?
$pwd
is an automatic variable. Its name stands for "present working directory" and it should always contain the current working path.
You can use just "." or ".\" as a path parameter to represent the current location, but you can't set a variable to .\ and have it then contain the current path, so in this regard they are different.
As an example if you were writing some script logic that needed to check the current working directory you would need to use $pwd
vs .\
. For example:
if ($pwd -eq 'c:\some\path') { }
Would work. However:
if (. -eq 'c:\some\path') { }
Would not.
$PWD
and Get-Location
(alias: pwd
) give you an absolute path, .
is a relative path. This can be important when storing a path to re-use later (e.g. in a different location), where .
will always be relative to the current location.
Resolve-Path
the result is the same. But you chose to omit that tidbit from your comment ;-) I just noticed that Resolve-Path
doesn't work like I thought it would anyway; I omitted that part again. –
Evoy © 2022 - 2024 — McMap. All rights reserved.