5
괄호 사이에 표현식을 삽입 할 때 두 개의 다른 멤버 목록을 얻는 이유가 궁금합니다. gl -stack
. 괄호가 없으면 표현식이 완전히 평가되고 결과가 다음 파이프 라인 구성 요소로 즉시 전달되는 것 같습니다. 그러나 괄호를 사용하면 컬렉션 내의 단일 개체가 하나씩 전달되므로 컬렉션 자체의 개체 대신 컬렉션의 개체에 대해 Get-Member
이 호출됩니다. Get-Location -Stack
의 예를 보려면 다음 PowerShell 상호 작용을 참조하십시오."(gl -stack)"과 "gl-stack"의 차이점
미리 감사드립니다.
PS C:\temp\loc1> pushd
PS C:\temp\loc1> pushd ..\loc2
PS C:\temp\loc2> gl -stack
Path
----
C:\temp\loc1
C:\temp\loc1
PS C:\temp\loc2> gl -stack | gm
TypeName: System.Management.Automation.PathInfoStack
Name MemberType Definition
---- ---------- ----------
Clear Method System.Void Clear()
Contains Method bool Contains(System.Management.Automation.PathInfo...
CopyTo Method System.Void CopyTo(System.Management.Automation.Pat...
Equals Method bool Equals(System.Object obj)
GetEnumerator Method System.Collections.Generic.Stack`1+Enumerator[[Syst...
GetHashCode Method int GetHashCode()
GetType Method type GetType()
Peek Method System.Management.Automation.PathInfo Peek()
Pop Method System.Management.Automation.PathInfo Pop()
Push Method System.Void Push(System.Management.Automation.PathI...
ToArray Method System.Management.Automation.PathInfo[] ToArray()
ToString Method string ToString()
TrimExcess Method System.Void TrimExcess()
Count Property System.Int32 Count {get;}
Name Property System.String Name {get;}
PS C:\temp\loc2> (gl -stack) | gm
TypeName: System.Management.Automation.PathInfo
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Drive Property System.Management.Automation.PSDriveInfo Drive {get;}
Path Property System.String Path {get;}
Provider Property System.Management.Automation.ProviderInfo Provider {...
ProviderPath Property System.String ProviderPath {get;}
고맙습니다. 위의 절차를 설명하는 '공식'도움말 페이지 나 MSDN과 비슷한 링크가 있습니까? 나는 많은 것을 수색했으나 이것에 대한 어떤 정보도 찾을 수 없었다. – DAXaholic
퍼즐 한 조각이 있습니다. cmdlet이 Get-Location과 같은 출력을 사용하여 파이프 라인에 출력하는 WriteObject 메서드가 있습니다. 다음은 과부하 중 하나에 대한 링크입니다. http://msdn.microsoft.com/en-us/library/ms568370(v=vs.85).aspx. cmdlet은 개체를 파이프 라인에 "있는 그대로"배치할지 또는 PowerShell이 개체를 열거하는지 (컬렉션이라고 가정 함) 여부를 선택할 수 있으며 열거 항목을 파이프 라인에 배치 할 수 있습니다. BTW 변수에 지정할 경우 동일한 그룹화 식 동작을 볼 수 있습니다. '$ arr = GetArray; $ arr | % {$ _. GetType(). 이름}}' –