zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Sweth Chandramouli <svc@sweth.net>, ZSH Users <zsh-users@sunsite.dk>
Subject: Re: zsh dumping core because I don't grok TRAPEXIT
Date: Sat, 8 Sep 2001 07:12:05 +0000	[thread overview]
Message-ID: <1010908071206.ZM18774@candle.brasslantern.com> (raw)
In-Reply-To: <20010908021331.A14998@astaroth.sweth.net>

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   


      reply	other threads:[~2001-09-08  7:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-07 22:04 Sweth Chandramouli
2001-09-08  5:50 ` Bart Schaefer
2001-09-08  6:13   ` Sweth Chandramouli
2001-09-08  7:12     ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1010908071206.ZM18774@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=svc@sweth.net \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).