
다음을 수행하여 명령 myHandler()
전에 함수를 실행할 수 있습니다.bash
function myHandler() {
...
}
trap 'myHandler' DEBUG
그러나 다음과 같이 BASH_COMMAND
런타임 조건에 따라 예정된 작업을 계속하거나 중단 할 수 있기를 원합니다 .myHandler
function myHandler() {
if ! myCondition ; then
abort the execution of BASH_COMMAND right here
fi
# Proceed with the execution of BASH_COMMAND
}
가능합니까?
답변1
0 이 extdebug
아닌 코드(extdebug
옵션 설명 보기) 에서 myHandler
:
$ function myHandler() {
if [[ $SKIP = "true" ]]; then return 1; fi;
echo 'myHandler execute'
}
$ trap 'myHandler' DEBUG
$ shopt -s extdebug
$ echo 1
myHandler execute
1
$ SKIP=true
myHandler execute
$ echo 1