From owner-freebsd-questions@FreeBSD.ORG Mon Jul 21 06:05:05 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DA60F37B4CE for ; Mon, 21 Jul 2003 06:05:05 -0700 (PDT) Received: from corb.mc.mpls.visi.com (corb.mc.mpls.visi.com [208.42.156.1]) by mx1.FreeBSD.org (Postfix) with ESMTP id 20EFA43FBD for ; Mon, 21 Jul 2003 06:05:05 -0700 (PDT) (envelope-from hawkeyd@visi.com) Received: from sheol.localdomain (hawkeyd-fw.dsl.visi.com [208.42.101.193]) by corb.mc.mpls.visi.com (Postfix) with ESMTP id 455AE81E2 for ; Mon, 21 Jul 2003 08:05:04 -0500 (CDT) Received: (from hawkeyd@localhost) by sheol.localdomain (8.11.6p2/8.11.6) id h6LD53k06676 for freebsd-questions@freebsd.org; Mon, 21 Jul 2003 08:05:03 -0500 (CDT) (envelope-from hawkeyd) X-Spam-Policy: http://www.visi.com/~hawkeyd/index.html#mail Date: Mon, 21 Jul 2003 08:05:03 -0500 From: D J Hawkey Jr To: questions at FreeBSD Message-ID: <20030721130503.GA6427@sheol.localdomain> References: <20030721122557.GA6212@sheol.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030721122557.GA6212@sheol.localdomain> User-Agent: Mutt/1.4.1i Subject: Re: Stupid shell tricks X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: hawkeyd@visi.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Jul 2003 13:05:06 -0000 I got it! > I'll cut right to it: I'm looking for a technique to do "atomic writes" > in a shell (sh(1)) script, playing with the trap builtin. It goes something > like this: > > 1: #!/bin/sh > 2: > 3: trapper () > 4: { > 5: rm -f $TMPFILE > 6: exit > 7: } > 8: > 9: trap trapper HUP PIPE INT QUIT SEGV > 10: > 11: ... > 12: > 13: while read LINE; do > 14: trap "" HUP PIPE INT QUIT SEGV > 15: binary_that_writes $LINE > 16: ... > 17: done <$TMPFILE > 18: > 19: trapper I ditched line 14, and changed line 15 to: sh -c "trap \"\" HUP PIPE INT QUIT SEGV; binary_that_writes $LINE" The explanation of "-T" in the man page gave me the clue. Movin' right along, Dave -- ______________________ ______________________ \__________________ \ D. J. HAWKEY JR. / __________________/ \________________/\ hawkeyd@visi.com /\________________/ http://www.visi.com/~hawkeyd/