![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | What is $pwd exactly? I suppose it is Process Working Directory or something similar, isn't? There are some issues that I can't explain: *) I can change $pwd (accidentally or not), then its value is different from both Get-Location and [environment]::CurrentDirectory. *) I can even remove variable $pwd at all (accidentally or not) simply by Remove-Variable pwd. Then in both cases code that uses $pwd does not work "correctly". So, what is $pwd exactly and how/why to use it? -- Thanks, Roman |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: What is $pwd exactly? The explanation - which you already know I bet <g> - is that a readily-modified variable is not a good place to store absolute reference information. There's also a potential cognitive problem - one might expect that $pwd = "Kaua'i, Hawaii" would either set the location or return an error message; since there is no error, we have a clear breach of contract. ![]() I would REALLY favor exposing information as a set of properties rather than raw variables, unless PowerShell is going to implement validation for variables in a future version. "Roman Kuzmin" <RomanKuzmin@discussions.microsoft.com> wrote in message news:388D9CA6-6E24-4B7C-8233-E06240B9D57F@microsoft.com... >I suppose it is Process Working Directory or something similar, isn't? >There > are some issues that I can't explain: > > *) I can change $pwd (accidentally or not), then its value is different > from > both Get-Location and [environment]::CurrentDirectory. > > *) I can even remove variable $pwd at all (accidentally or not) simply by > Remove-Variable pwd. > > Then in both cases code that uses $pwd does not work "correctly". So, what > is $pwd exactly and how/why to use it? > > -- > Thanks, > Roman |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: What is $pwd exactly? My understanding is that $pwd is the PowerShell Working Directory which is different then the working directory of the normal Windows command shell. The reason for having two different "working directories" is that the working directory in PowerShell can be more than just a folder on the hard drive. For example, registry hives are mapped to "drives" so you could use folder navigation semantics to navigate the registry. If you did "set-location hklm:\" in PowerShell that's works just fine, but only the PowerShell will know how to handle that as the current folder. On Dec 12, 5:15 am, Roman Kuzmin <RomanKuz...@discussions.microsoft.com> wrote: > So, what is $pwd exactly and how/why to use it? |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: What is $pwd exactly? That wasn't what he was getting at. It's the fact that $pwd is unprotected, making it something to avoid in code. Another demo: PS> set-location c:\temp PS> remove-variable pwd PS> "$pwd\script.config" \script.config PS> $pwd = "c:\windows\system32" PS> "$pwd\script.config" c:\windows\system32\script.config PS> Get-Location Path ---- C:\temp <rhy@rhy.com> wrote in message news:1165945295.409172.102980@79g2000cws.googlegroups.com... > My understanding is that $pwd is the PowerShell Working Directory which > is different then the working directory of the normal Windows command > shell. The reason for having two different "working directories" is > that the working directory in PowerShell can be more than just a folder > on the hard drive. For example, registry hives are mapped to "drives" > so you could use folder navigation semantics to navigate the registry. > If you did "set-location hklm:\" in PowerShell that's works just fine, > but only the PowerShell will know how to handle that as the current > folder. > > On Dec 12, 5:15 am, Roman Kuzmin > <RomanKuz...@discussions.microsoft.com> wrote: >> So, what is $pwd exactly and how/why to use it? > |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: What is $pwd exactly? In Unix PWD = Print Working Directory $pwd is a variable that does essentially the same thing. It contains the PathInfo object for the current location. PS>$pwd Path ---- C:\WINDOWS\system32\WindowsPowerShell\v1.0 PS>cd .. PS>$pwd Path ---- C:\WINDOWS\system32\WindowsPowerShell PS>cd HKLM:\Software PS>pwd Path ---- HKLM:\Software PS>$pwd | gm TypeName: System.Management.Automation.PathInfo Name MemberType Definition ---- ---------- ---------- Equals Method System.Boolean Equals(Object obj) GetHashCode Method System.Int32 GetHashCode() GetType Method System.Type GetType() get_Drive Method System.Management.Automation.PSDriveInfo get_Dri... get_Path Method System.String get_Path() get_Provider Method System.Management.Automation.ProviderInfo get_Pr... get_ProviderPath Method System.String get_ProviderPath() ToString Method System.String ToString() Drive Property System.Management.Automation.PSDriveInfo Drive {... Path Property System.String Path {get;} Provider Property System.Management.Automation.ProviderInfo Provid... ProviderPath Property System.String ProviderPath {get;} PS> "Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message news:eThZsyhHHHA.1280@TK2MSFTNGP04.phx.gbl... > That wasn't what he was getting at. It's the fact that $pwd is > unprotected, making it something to avoid in code. Another demo: > > PS> set-location c:\temp > PS> remove-variable pwd > PS> "$pwd\script.config" > \script.config > PS> $pwd = "c:\windows\system32" > PS> "$pwd\script.config" > c:\windows\system32\script.config > PS> Get-Location > > Path > ---- > C:\temp > > > <rhy@rhy.com> wrote in message > news:1165945295.409172.102980@79g2000cws.googlegroups.com... >> My understanding is that $pwd is the PowerShell Working Directory which >> is different then the working directory of the normal Windows command >> shell. The reason for having two different "working directories" is >> that the working directory in PowerShell can be more than just a folder >> on the hard drive. For example, registry hives are mapped to "drives" >> so you could use folder navigation semantics to navigate the registry. >> If you did "set-location hklm:\" in PowerShell that's works just fine, >> but only the PowerShell will know how to handle that as the current >> folder. >> >> On Dec 12, 5:15 am, Roman Kuzmin >> <RomanKuz...@discussions.microsoft.com> wrote: >>> So, what is $pwd exactly and how/why to use it? >> > > |
My System Specs![]() |
| | #6 (permalink) |
| Guest | Re: What is $pwd exactly? Hi Marcel, > In Unix PWD = Print Working Directory > > $pwd is a variable that does essentially the same thing. It contains the > PathInfo object for the current location. But why introducing a fragile variable named $pwd if there's already an alias pwd that does essentially the same? cu Max |
My System Specs![]() |
| | #7 (permalink) |
| Guest | Re: What is $pwd exactly? "Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote > That wasn't what he was getting at. It's the fact that $pwd is > unprotected, making it something to avoid in code. Yes, exactly. I did have a real problem with using $pwd and asked this question already having bad experience. From now on I do not use $pwd in my code. -- Thanks, Roman |
My System Specs![]() |
| | #8 (permalink) |
| Guest | Re: What is $pwd exactly? "Roman Kuzmin" <z@z.z> wrote in message news:ev9GpUqHHHA.1188@TK2MSFTNGP06.phx.gbl... > "Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote >> That wasn't what he was getting at. It's the fact that $pwd is >> unprotected, making it something to avoid in code. > > Yes, exactly. I did have a real problem with using $pwd and asked this > question already having bad experience. From now on I do not use $pwd in > my code. Further notes. ![]() + Unix This appears to be a ksh shell variable on Unix; see this page: http://node1.yo-linux.com/cgi-bin/ma...gi_command=ksh under the Parameters section. I don't have ksh on my system right now to test reliability, but here's what the man page says: PWD: The current working directory. Maybe unset or null if shell doesn't know where it is. So there clearly CAN be problems. + cmd.exe %CD% has the same issue, only more so. If you do this: set CD=foo then CD is foo no matter how many times you change directories until you do set CD= followed by a location change. Personally, I think it might be a good idea to make $pwd read-only. This would still allow forcing overwrite if you really, really, really want to fake it for some reason. |
My System Specs![]() |
| | #9 (permalink) |
| Guest | Re: What is $pwd exactly? "Maximilian Hänel" <ngSpam@smjh.de> wrote in message news:uEnWnqjHHHA.5104@TK2MSFTNGP03.phx.gbl... > Hi Marcel, > >> In Unix PWD = Print Working Directory >> >> $pwd is a variable that does essentially the same thing. It contains the >> PathInfo object for the current location. > > But why introducing a fragile variable named $pwd if there's already an > alias pwd that does essentially the same? I suspect it's because an alias executes whereas a variable doesn't (i.e. perhaps it gets updated statically as the Shell is used); the alias may be (or might be perceived to be) treated differently in more complex scripts that need to reference the $pwd as a string. Then again, I may be (or might be perceived to be) talking with hot air derived from my gut feelings and eminating from my backside. Jon |
My System Specs![]() |