본문 바로가기

Windows 10/PowerShell

PowerShell : If, ElseIf, Else

반응형

- 조건문 비교 연산자

조건문 비교시 보통의 연산자인 =, <, > 기호 대신 약자를 사용한다.

  • -eq : ==
  • -ne : !=
  • -lt : <
  • -le : <=
  • -gt : >
  • -ge : >=

 

- IF문

$name = "Seoul"

if($name -eq "seoul"){
    Write-Host "seoul == Seoul"
}
if($name -eq "Seoul"){
    Write-Host "Seoul == Seoul"
}

- IF & ELSEIF

$name = "Seoul"

if($name -eq "Busan"){
    Write-Host "Busan != Seoul"
}elseif($name -eq "Seoul"){
    Write-Host "Seoul == Seoul"
}

- IF & ELSE

$name = "Seoul"

if($name -eq "Busan"){
    Write-Host "Busan != Seoul"
}else{
    Write-Host "Seoul == Seoul"
}

- 주의점

  • elseif 사용시 else if로 쓰면 에러난다. (빈공간 없음)
  • if, elseif, else 사용시 무조건 대가로 { } 가 있어야 한다.

 

 

about_If

About If In this article --> SHORT DESCRIPTION Describes a language command you can use to run statement lists based on the results of one or more conditional tests. LONG DESCRIPTION You can use the If statement to run code blocks if a specified conditiona

docs.microsoft.com

 

about_Comparison_Operators

About Comparison Operators In this article --> Short description Describes the operators that compare values in PowerShell. Long description Comparison operators let you specify conditions for comparing values and finding values that match specified patter

docs.microsoft.com

 

 

반응형

'Windows 10 > PowerShell' 카테고리의 다른 글

PowerShell : Switch  (0) 2019.06.14
PowerSehll : For, While, Break  (0) 2019.06.14
PowerShell : 주석 처리  (0) 2019.06.14
PowerShell : 입력 & 출력  (0) 2019.06.14
PowerShll : 관리자로 실행  (0) 2019.06.14