본문으로 바로가기

메인 스크립트인지 판단하기

category Tcl & Tk/팁 (Tip) 2025. 10. 28. 09:52

간혹 스크립틀 작성 후 테스트 코드를 작성할 때 메인 스크립트인지 아닌지를 판단해야 할 필요가 있습니다.

이러한 판단은 아래와 같이 가능합니다.

# a.tcl

if {[info exists argv0] && ([file tail [info script]] eq [file tail $argv0])} {
	puts "this is main script"
} else {
	puts "this is sub script"
}

source b.tcl
# b.tcl

if {[info exists argv0] && ([file tail [info script]] eq [file tail $argv0])} {
	puts "this is main script"
} else {
	puts "this is sub script"
}

실행을 해보면 a.tcl은 메인 스크립트로, b.tcl은 서브 스크립트로 판단이 잘 됨을 확인할 수 있습니다.

$ tclsh85 a.tcl
this is main script
this is sub script

'Tcl & Tk > 팁 (Tip)' 카테고리의 다른 글

toplevel의 타이틀바를 감추고 아웃라인 그리기  (0) 2025.10.11
oobgexec1 0.1  (0) 2025.09.30
Tcl의 로고가 깃털인 이유  (0) 2025.09.05
값 호출과 참조 호출  (0) 2025.09.05
Tcl 8.5의 임의 정밀도 계산  (0) 2025.09.01