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 prints the directory you are currently in. It does nothing else. pwd does not take any arguments. cd without arguments changes your working directory to your home directory.
pwd stands for Print Working Directory. It prints the path of the working directory, starting from the root. pwd is shell built-in command(pwd) or an actual binary(/bin/pwd). $PWD is an environment variable which stores the path of the current directory.
The pwd Linux command prints the current working directory path, starting from the root ( / ). Use the pwd command to find your way in the Linux file system structure maze or to pass the working directory in a Bash script.
'pwd' stands for 'Print Working Directory'. As the name states, command 'pwd' prints the current working directory or simply the directory user is, at present. It prints the current directory name with the complete path starting from root (/).
$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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With