Reputation: 1317
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?
Upvotes: 5
Views: 5511
Reputation: 354734
$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.
Upvotes: 5
Reputation: 23395
$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.
Upvotes: 10