about_Reserved_Words

about_Reserved_Words

PowerShell에는 특별한 의미를 가진 단어들이 있어요. 이런 단어들을 식별자로 쓰면 안 되는 이유가, 바로 그 '특별한 의미' 때문인데요. 오늘은 그 예약어(reserved words)가 무엇이고 어떻게 다뤄야 하는지 하나씩 짚어볼게요.

출처: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_reserved_words

본문

PowerShell에는 특별한 의미를 가진 몇몇 단어가 있어요. 이런 단어를 따옴표 없이 쓰면, PowerShell은 그 단어를 문자열로 취급하지 않고 그 특별한 의미를 적용하려고 해요. 명령이나 스크립트에서 이런 단어를 그 특별한 의미 없이 매개 변수(parameter) 인자로 쓰고 싶다면, 예약어를 따옴표로 감싸면 돼요.

PowerShell의 예약어는 다음과 같아요:

assembly         exit            process
base             filter          public
begin            finally         return
break            for             sequence
catch            foreach         static
class            from (*)        switch
command          function        throw
configuration    hidden          trap
continue         if              try
data             in              type
define (*)       inlinescript    until
do               interface       using
dynamicparam     module          var (*)
else             namespace       while
elseif           parallel        workflow
end              param
enum             private

(*) These keywords are reserved for future use.

몇몇 언어 키워드는 foreach, if, for, while처럼 각자 전용 도움말 문서를 갖고 있어요. 이 글들을 보려면 Get-Help about_에 키워드를 붙여 입력하면 되죠. 예를 들어 foreach 문에 대한 정보를 얻으려면 이렇게 입력해요:

Get-Help about_Foreach

filter 문이나 return 문의 구문에 대한 정보는 이렇게 입력하면 돼요:

Get-Help about_Functions

그 밖의 예약어에 대한 정보는 이렇게요:

Get-Help <Reserved_Word>

Note

모든 예약어가 전용 도움말 문서를 갖고 있는 건 아니에요. Get-Help가 문서를 반환하지 않는다면, 해당 예약어를 다루는 문서를 다음 명령으로 검색해볼 수 있어요:

Get-Help <Reserved_Word> -Category:HelpFile

더 알아보기