#! /usr/bin/perl -w use strict; for (@ARGV) { my $source = $_; next unless -l $source; my $target = readlink $source or die "readlink: $!"; my $trap = sub { unlink $source; symlink $target, $source; print "Caught a SIG$_[0]!\n"; exit; }; local ($SIG{HUP}, $SIG{INT}, $SIG{TERM}, $SIG{QUIT}, $SIG{__DIE__}) = ($trap, $trap, $trap, $trap, $trap); unlink $source; system '/bin/cp', $target, $source; }