d31f96eacff7f7ef95b1929ffa007183a0b8255a
[p5sagit/p5-mst-13.2.git] / eg / relink
1 #!/usr/bin/perl
2 'di';
3 'ig00';
4 #
5 # $Header: relink,v 3.0.1.2 90/08/09 03:17:44 lwall Locked $
6 #
7 # $Log: relink,v $
8 # Revision 3.0.1.2  90/08/09  03:17:44  lwall
9 # patch19: added man page for relink and rename
10
11
12 ($op = shift) || die "Usage: relink perlexpr [filenames]\n";
13 if (!@ARGV) {
14     @ARGV = <STDIN>;
15     chop(@ARGV);
16 }
17 for (@ARGV) {
18     next unless -l;             # symbolic link?
19     $name = $_;
20     $_ = readlink($_);
21     $was = $_;
22     eval $op;
23     die $@ if $@;
24     if ($was ne $_) {
25         unlink($name);
26         symlink($_, $name);
27     }
28 }
29 ##############################################################################
30
31         # These next few lines are legal in both Perl and nroff.
32
33 .00;                    # finish .ig
34  
35 'di                     \" finish diversion--previous line must be blank
36 .nr nl 0-1              \" fake up transition to first page again
37 .nr % 0                 \" start at page 1
38 ';<<'.ex'; #__END__ ############# From here on it's a standard manual page ############
39 .TH RELINK 1 "July 30, 1990"
40 .AT 3
41 .SH LINK
42 relink \- relinks multiple symbolic links
43 .SH SYNOPSIS
44 .B relink perlexpr [symlinknames]
45 .SH DESCRIPTION
46 .I Relink
47 relinks the symbolic links given according to the rule specified as the
48 first argument.
49 The argument is a Perl expression which is expected to modify the $_
50 string in Perl for at least some of the names specified.
51 For each symbolic link named on the command line, the Perl expression
52 will be executed on the contents of the symbolic link with that name.
53 If a given symbolic link's contents is not modified by the expression,
54 it will not be changed.
55 If a name given on the command line is not a symbolic link, it will be ignored.
56 If no names are given on the command line, names will be read
57 via standard input.
58 .PP
59 For example, to relink all symbolic links in the current directory
60 pointing to somewhere in X11R3 so that they point to X11R4, you might say
61 .nf
62
63         relink 's/X11R3/X11R4/' *
64
65 .fi
66 To change all occurences of links in the system from /usr/spool to /var/spool,
67 you'd say
68 .nf
69
70         find / -type l -print | relink 's#/usr/spool#/var/spool#'
71
72 .fi
73 .SH ENVIRONMENT
74 No environment variables are used.
75 .SH FILES
76 .SH AUTHOR
77 Larry Wall
78 .SH "SEE ALSO"
79 ln(1)
80 .br
81 perl(1)
82 .SH DIAGNOSTICS
83 If you give an invalid Perl expression you'll get a syntax error.
84 .SH BUGS
85 .ex