0015. [ debug ] ksh 실행 디버깅 코맨드와 옵션
코맨드 |
기능 |
동작설명 |
ksh -x script |
에코우기능 |
실행되기전에 변수 대체가 된 상태로 스크립트의 각 줄을 출력시켜준다 |
ksh -v script |
verbose옵션 |
실행되기전에 스크립트에 입력된 상태로 각 줄을 출력시켜준다 |
ksh -n script |
noexec옵션 |
스크립트의 각줄을 해석은 해주지만 실행은 시키지 않는다 |
set -x |
echo on |
스크립트 실행 추적한다 |
set -o xtrace |
||
set +x |
echo off |
추적기능을 해제 시킨다 |
typeset -ft |
추적옵션 on |
함수에서의 실행 추적을 한다 |
PS4 |
export PS4=$LINENO PS4 프롬프트의 디폴트 값은 + 기호이다. 프롬프트를 리셋시킬수 있다. 여기서는 줄 번호가 각 줄에 대해서 출력된다 |
|
trap DEBUG |
trap 'print $LINENO' DEBUG 스크립트 각줄에 대한 $LINENO 값을 출력시킨다. 각 스크립트 코맨드마다 트랙 동작이 수행된다 |
|
trap ERR |
trap 'print Bad Input' ERR 0 이 아닌 exit status 값이 되돌려지면 trap 이 실행된다 |
|
trap EXIT |
trap 'print Exiting from $0' EXIT 스크립트나 함수가 종료하면 메시지가 출력된다 |
|
#!/bin/ksh name="horany" if [[ $name = [Hh]* ]] then print Hi $name fi num=1 while (( num < 5 )) do (( num=num+1 )) done print The grand total is $num |
||
#!/bin/ksh trap 'print "num=$num on line $LINENO"' DEBUG num=1 while (( num < 5 )) do (( num = $num + 1 )) done print The grand total is $num |
||
$LINENO 는 현재 스크립트의 줄수를 갖는 특수 Korn Shell 변수이다. |
'IT' 카테고리의 다른 글
0017. [ trap ] trap 함수 호출 예제 (0) | 2015.06.30 |
---|---|
0016. [ coprocess ] 코프로세스 (0) | 2015.06.30 |
0014. [ getopts ] getopts 스크립트 사용법1 (0) | 2015.06.30 |
0013. [ getopts ] getopts 스크립트 사용법2 (0) | 2015.06.30 |
0012. [ getopts ] getopts 스크립트 사용법3 (0) | 2015.06.30 |
0014. [ getopts ] getopts 스크립트 사용법1
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 |
'IT' 카테고리의 다른 글
0016. [ coprocess ] 코프로세스 (0) | 2015.06.30 |
---|---|
0015. [ debug ] ksh 실행 디버깅 코맨드와 옵션 (0) | 2015.06.30 |
0013. [ getopts ] getopts 스크립트 사용법2 (0) | 2015.06.30 |
0012. [ getopts ] getopts 스크립트 사용법3 (0) | 2015.06.30 |
0011. [ getopts ] getopts 스크립트 사용법4 (0) | 2015.06.30 |
0013. [ getopts ] getopts 스크립트 사용법2
옵션 리스트 앞에 콜론이 옴으로 해서 Korn shell 이 유효하지 않은 옵션이 입력되더라도 에러 메시지를 내지 못하도록 한다. 하지만 욥션이 유효하지 못하면 ? 기호가 options 변수에 지정된다. 그리고 OPTARG 변수에 유효하지 않은 옵션이 지정된다 |
#!/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";; \?) print "$OPTARG is not a valid option" 1>&2 ;; esac done |
$opts2 -x $opts2 -y $opts2 -xy $opts2 -yx $opts2 xy $opts2 -a $opts2 -c |
'IT' 카테고리의 다른 글
0015. [ debug ] ksh 실행 디버깅 코맨드와 옵션 (0) | 2015.06.30 |
---|---|
0014. [ getopts ] getopts 스크립트 사용법1 (0) | 2015.06.30 |
0012. [ getopts ] getopts 스크립트 사용법3 (0) | 2015.06.30 |
0011. [ getopts ] getopts 스크립트 사용법4 (0) | 2015.06.30 |
0010. [ 보안 ] ksh 보안 스크립트 적용하기 (0) | 2015.06.29 |
0012. [ getopts ] getopts 스크립트 사용법3
+d 는 유효한 옵션이다. +d 는 + 와 같이 options 변수에 저장된다. print 코맨드에 -R 옵션을 주면 - 를 print 스트링의 첫번째 문자로 사용될 수 가 있다. |
#!/bin/ksh while getopts :d options do case $options in d) print -R "-d is the ON switch";; +d) print -R "+d is the OFF switch";; \?) print "$OPTARG is not a valid option";; esac done |
$opts3 -d $opts3 +d $opts3 -e $opts3 e |
'IT' 카테고리의 다른 글
0014. [ getopts ] getopts 스크립트 사용법1 (0) | 2015.06.30 |
---|---|
0013. [ getopts ] getopts 스크립트 사용법2 (0) | 2015.06.30 |
0011. [ getopts ] getopts 스크립트 사용법4 (0) | 2015.06.30 |
0010. [ 보안 ] ksh 보안 스크립트 적용하기 (0) | 2015.06.29 |
0009. [ script ] killbatch.sh (0) | 2015.06.29 |
0011. [ getopts ] getopts 스크립트 사용법4
getopts :x: 로 뒤에 : 는 반드시 인자가 와야 한다는 것을 의미한다 |
#!/bin/ksh alias USAGE='print "Usage : opts4 [-x] filename" >$2' while getopts :x: arguments do case $arguments in x) print "$OPTARG is the name of the argument";; :) print "please enter an argument after the -x option" >&2 USAGE;; \?) print "$OPTARG is not a valid option" >&2 USAGE;; esac print "$OPTIND" done |
$opts4 -x $opts4 -x horany $opts4 x $opts4 x horany |
'IT' 카테고리의 다른 글
0013. [ getopts ] getopts 스크립트 사용법2 (0) | 2015.06.30 |
---|---|
0012. [ getopts ] getopts 스크립트 사용법3 (0) | 2015.06.30 |
0010. [ 보안 ] ksh 보안 스크립트 적용하기 (0) | 2015.06.29 |
0009. [ script ] killbatch.sh (0) | 2015.06.29 |
0008. [nawk if else] groupvalue inser문 생성 script (0) | 2015.06.29 |