Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between "$pwd" and "./"?

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?

like image 423
J. Doe Avatar asked Feb 22 '18 08:02

J. Doe


People also ask

What is difference between pwd and cd commands explain?

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.

What is the use of the $PWD variable?

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.

What does pwd mean in bash?

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.

What is pwd present working directory?

'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 (/).


2 Answers

$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.

like image 179
Mark Wragg Avatar answered Oct 04 '22 23:10

Mark Wragg


$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.

like image 38
Joey Avatar answered Oct 05 '22 00:10

Joey