On Fri, Jun 20, 2025 at 09:21:28AM -0400, Michael Stone wrote:
> I agree with this, and question why the austin group is considering it at
> all.
well. I shell almost every day for about 30 years now and I'm really
happy about this because sponge is so convenient.
I wrote my own version of it (called bob) because I needed a -u (update)
flag: change the dest only if the new content differs to the old one.
Usecase:
* an awk script generating hundred of dot files from 1 index file
* a Makefile to get postscript files out of the dotfiles
so
print > base".dot"
became
print | "bob -u "base".dot"
and I spared many dot commands.
> The atomicity guarantees in sponge are too contingent and not
> discoverable (at least without as much work as it would take to reimplement
> sponge).
yet, the only thing to get it is just to close stdin before opening the
dest. a simplified perl version of bob would be:
#! /usr/bin/env perl
use strict;
use warnings;
use autodie;
# all inputs will be slurped as raw bytes
use open qw< :std IO :raw >;
my $dest = shift or die "a dest file expected";
undef $/; # slurp mode :)
my $in = <STDIN>; close STDIN;
$_ = do {
open my $fh, '<' , $dest;
<$fh>
};
exit if $_ eq $in;
open my $fh, '>' , $dest;
print $fh $in;
--
Marc Chantreux
Pôle CESAR (Calcul et services avancés à la recherche)
Université de Strasbourg
14 rue René Descartes,
BP 80010, 67084 STRASBOURG CEDEX
03.68.85.60.79