본문 바로가기
Windows/PowerShell

[PowerShell] 연산자 목록 예시

by 지혜를 탐구하는 오딘 2022. 5. 28.
반응형
반응형

 

산술 연산자 (더하기, 빼기, 곱하기 나누기 사칙연산 할 때)

 

+    더하기

-    빼기

*    곱하기

/    나누기

%    나머지

++    1더하기

--    1빼기

 

나누기로 정수 부분만 구하고 싶다면,

[int]( 4 / 3 )    # 결괏값 1

(소수점에서 버림)

 

비교 연산자 (True False 구분할 때)

-eq    "EQual to", 같다, ==

-ne    "Not Equal to", 같지 않다, !=

-gt    "Greater Than", 보다 크다, >

-lt    "Less Than", 보다 작다, <

-ge    "Greater than or Equal to", 크거나 같다, >=

-le    "Less than or Equal to", 작거나 같다, <=

 

 

논리 연산자 (조건부)

-and    "and", 그리고, &&

-or    "or", 또는, ||

-not    "not", 아니라면, !

-xor    "xor", 또는(FALSE라면 TRUE), ! || 조합

 

 

 

테스트 코드

"`n`n`n"
"`tPowerShell 실행!"
"++++++++++++++++++++++++++++++++++++++++++++"

$isTrue = (3 > 2) # 값이 없다

if ($isTrue)
{
    "TRUE"
}

"--DELIMETER-----------------------------------"

$isTrue = (3 -eq 2) # 결괏값은 FALSE

if ($isTrue) # if문을 타지 않는다.
{
    "True"
}

"--DELIMETER-----------------------------------"

$isTrue = (3 -eq 2) # 결괏값은 FALSE

if (!$isTrue) # if문을 탄다!
{
    "3 is equal to 2 --> -eq"
    "FALSE"
}

"--DELIMETER-----------------------------------"

$isTrue = (3 -ne 2) # 결괏값은 TRUE

if ($isTrue) # if문을 탄다!
{
    "3 is Not Equal to 2 --> -ne"
    "True"
}


"--DELIMETER-----------------------------------"

$isTrue = (3 -gt 2) # 3은 2 보다 크다, 3 > 2)

if ($isTrue)
{
    "3 is Greater Than 2 --> -gt"
    "TRUE"
}

"--DELIMETER-----------------------------------"
 
if (2 -lt 3)
{
    "2 is Less Than 3 --> -lt"
    "TRUE"
}


"--DELIMETER-----------------------------------"

if (2 -le 3)
{
    "2 is Less than or Equal to 3 --> -le"
    "TRUE"
}

"--DELIMETER-----------------------------------"

if (3 -ge 3)
{
    "3 is Greater than or Equal to 3 --> -ge"
    "TRUE"
}

"++++++++++++++++++++++++++++++++++++++++++++"
"`tPowerShell 끝!"

 

 

(참고 자료)

https://docs.microsoft.com/ko-kr/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.2

728x90
반응형

댓글