2014-03-07 3 views
1

스코프?파워 쉘은 PowerShell 콘솔에서

은 더욱 혼란 그때 할 경우 :

PS C:\Users\Moomin\Documents> $myVar = $null 
PS C:\Users\Moomin\Documents> $global:myVar 

나는 아무것도 반환되지 얻을. 나는 global을 돌려 줄 것으로 예상했다. MS에서

답변

3

범위는 전역에서 작동하는 기능이 아닌 콘솔을 사용하는 경우의 기능을 기반으로합니다.

PS C:\> $myvar = 4 
PS C:\> function PrintMyVar{$myvar = 6;$myvar} 
PS C:\> PrintMyVar 
6 
PS C:\> $myvar 
4 
2

는 about_scope : $myVar 덮어 쓰기됩니다 아무것도 마지막 줄에 반환되지 않습니다 이유는

Local: 
    The current scope. The local scope can be the global 
    scope or any other scope. 

입니다.