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