IT

0014. [ getopts ] getopts 스크립트 사용법1

띠앗머리 2015. 6. 30. 07:58

getopts 코맨드는 while 코맨드의 조건식으로 사용된다. 프로그램의 유효한 옵션들인 x y getopts 코맨드 다음에 리스트니ㅏ. 옵션들은 루프의 몸체에서 차례로 테스트된다. 그리고 이들 옵션등은 - 없는 상태로 options 차례로 지정된다. 처리할 인자가 이상 없으면 getopts 0 아닌 exit status 값을 가지고 종료한다. 그러면 while 루프도 같이 따라 종료된다.

#!/bin/ksh

while getopts xy options

do

 case $options in

  x) print "you entered -x as an option";;

  y) print "you entered -y as an option";;

 esac

done

$opts -x

$opts -y

$opts -xy

$opts -yx

$opts -a

$opts x