Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Jul 2003 08:05:03 -0500
From:      D J Hawkey Jr <hawkeyd@visi.com>
To:        questions at FreeBSD <freebsd-questions@freebsd.org>
Subject:   Re: Stupid shell tricks
Message-ID:  <20030721130503.GA6427@sheol.localdomain>
In-Reply-To: <20030721122557.GA6212@sheol.localdomain>
References:  <20030721122557.GA6212@sheol.localdomain>

next in thread | previous in thread | raw e-mail | index | archive | help
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/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030721130503.GA6427>