Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zsh dumping core because I don't grok TRAPEXIT
- X-seq: zsh-users 4206
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Sweth Chandramouli <svc@xxxxxxxxx>, ZSH Users <zsh-users@xxxxxxxxxx>
- Subject: Re: zsh dumping core because I don't grok TRAPEXIT
- Date: Sat, 8 Sep 2001 07:12:05 +0000
- In-reply-to: <20010908021331.A14998@xxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20010907180418.A13819@xxxxxxxxxxxxxxxxxx> <1010908055006.ZM18450@xxxxxxxxxxxxxxxxxxxxxxx> <20010908021331.A14998@xxxxxxxxxxxxxxxxxx>
On Sep 8, 2:13am, Sweth Chandramouli wrote:
}
} OK. The more I think about it, though, the less I see
} when TRAPEXIT would really be useful. How would
}
} function TRAPEXIT {
} do_something
} }
} do_other_thing
}
} ever be different than
}
} do_other_thing ; do_something
When do_other_thing is a shell function, and do_something wants to use
the local variables of that function.
Also, it's an encapsulation issue: inside do_other_thing may be the best
place to control which do_something to do.
Finally, and a point I forgot to mention: TRAPEXIT preserves $?, so
it's actually like writing
do_other_thing; x=$? ; do_something ; return $x
For example:
getpass() {
TRAPEXIT() { stty echo }
stty -echo
read passwd || return 1
print
}
Without the trap, you'd at the least have to write something like
getpass() {
stty -echo
read passwd || { stty echo ; return 1 }
print
stty echo
}
Note that you can also do
TRAPINT TRAPQUIT TRAPEXIT () { stty echo }
to create three traps at once, although unless you `setopt localtraps'
only the TRAPEXIT will automatically remove itself.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
Messages sorted by:
Reverse Date,
Date,
Thread,
Author