chiark / gitweb /
pwhich: A portable (I believe) /bin/sh implementation of 'which'.
[bin.git] / desymlink
1 #! /usr/bin/perl -w
2 use strict;
3
4 for (@ARGV) {
5     my $source = $_;
6     next unless -l $source;
7     my $target = readlink $source or die "readlink: $!";
8     my $trap = sub { unlink $source;
9                      symlink $target, $source;
10                      print "Caught a SIG$_[0]!\n";
11                      exit; };
12     local ($SIG{HUP}, $SIG{INT}, $SIG{TERM}, $SIG{QUIT}, $SIG{__DIE__}) =
13         ($trap, $trap, $trap, $trap, $trap);
14     unlink $source;
15     system '/bin/cp', $target, $source;
16 }