티스토리 뷰

기본적인 switch


일단 기본적인 switch 문입니다. 
C를 하셨다고 가정하고 금방 이해하실 것이라고 봅니다 ㅋㅋ 


$computername = read-host 'Enter computer name'

switch($computername){

'com1'{

write "aaaa"

}

'com2'{

write "bbbb"

}

default {

write 'cccc'

}

}


wildcard switch


두 번째는 와일드 카드를 옵션을 넣은 swtich 문입니다. 

* 의 의미는 대부분 아실 것이라 생각됩니다. 간단히 모든 것이라는 의미인데

wildcard 옵션을 주고나서 *을 붙여주면 aaa로 시작되는 모든 것을 case로 인식합니다. 


$computername = read-host

switch -wildcard($computername){

'aaa*'{

write "aaaa"

}

'*bbb'{

write "bbbb"

}

default {

write 'cccc'

}

}



'Programming > Powershell' 카테고리의 다른 글

powershell Script 반복문  (0) 2017.03.20
powershell Script if문  (0) 2017.03.20
powershell Script 함수  (0) 2017.03.20
powershell Script 파라미터, 변수의 유효 범위  (0) 2017.03.20
powershell Script 주석, 도움말 넣기  (0) 2017.03.20
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함