I have a bash script which calls a .tcl script through which I'm running tksurfer. It works, except the script is no longer exiting when it reaches the end. Instead, it displays the tksurfer window and stays open. After I click the menu option to Quit, the script continues.

Below is the script

open_window

set lablpth "$env(SUBJECTS_DIR)/$env(SUBJECT_NAME)/label"
set outpth "$env(SUBJECTS_DIR)/$env(SUBJECT_NAME)/shots"

labl_import_annotation "$lablpth/$hemi.$env(PARC).annot"
redraw
UpdateAndRedraw

puts "Taking Snapshots..."

if {![file exists "$outpth/$env(SUBJECT_NAME)_${hemi}_$env(SURF)_$env(PARC)_lat.tif"]} {
make_lateral_view
redraw
set tiff "$outpth/$env(SUBJECT_NAME)_${hemi}_$env(SURF)_$env(PARC)_lat.tif"
save_tiff $tiff
}

if {![file exists "$outpth/$env(SUBJECT_NAME)_${hemi}_$env(SURF)_$env(PARC)_med.tif"]} {
make_lateral_view
rotate_brain_y 180
redraw
set tiff "$outpth/$env(SUBJECT_NAME)_${hemi}_$env(SURF)_$env(PARC)_med.tif"
save_tiff $tiff
}

exit(0)