Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacement for `pwd` in Windows PowerShell

Tags:

powershell

pwd

I have a Unix script which uses the command

Current_Dir=`pwd`

What would be the suitable replacement for it in Windows Power shell script?

like image 346
user2879237 Avatar asked Feb 18 '14 06:02

user2879237


People also ask

Does pwd work in PowerShell?

pwd (print working directory) in PowerShell get current path of current working directory to the standard output. PowerShell pwd is an alias of Get-Location cmdlet in PowerShell. $pwd automatic variable is type of System. Management.

How do you pwd in PowerShell?

Just use "pwd", or "Get-Location" ("pwd" is just an alias for "Get-Location"). ALso: you don't need the quotes in PS, like you do in a Unix shell. Show activity on this post. Powershell has many of the same commands as Linux.

What does pwd mean in PowerShell?

$PWD. Contains a path object that represents the full path of the current directory location for the current PowerShell runspace.

What does $_ in PowerShell?

The “$_” is said to be the pipeline variable in PowerShell. The “$_” variable is an alias to PowerShell's automatic variable named “$PSItem“. It has multiple use cases such as filtering an item or referring to any specific object.


2 Answers

Both of these are valid if you are trying to make a var with your current dir:

$current_directory = (pwd).path
$current_directory = pwd

The development team for Powershell contains a couple of Unix guys, so there are some goodies in there like ls, pwd and cat

like image 95
Vasili Syrakis Avatar answered Sep 25 '22 07:09

Vasili Syrakis


Use the $pwd.Path expression

write-host $pwd.Path
like image 43
JaredPar Avatar answered Sep 24 '22 07:09

JaredPar