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?
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.
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.
$PWD. Contains a path object that represents the full path of the current directory location for the current PowerShell runspace.
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.
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
Use the $pwd.Path
expression
write-host $pwd.Path
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