perl 5.0 alpha 2
[p5sagit/p5-mst-13.2.git] / eg / relink
CommitLineData
9f68db38 1#!/usr/bin/perl
00bf170e 2'di';
3'ig00';
4#
79072805 5# $RCSfile: relink,v $$Revision: 4.1 $$Date: 92/08/07 17:20:29 $
00bf170e 6#
7# $Log: relink,v $
79072805 8# Revision 4.1 92/08/07 17:20:29 lwall
9# Stage 6 Snapshot
10#
fe14fcc3 11# Revision 4.0 91/03/20 01:11:40 lwall
12# 4.0 baseline.
13#
00bf170e 14# Revision 3.0.1.2 90/08/09 03:17:44 lwall
15# patch19: added man page for relink and rename
16#
9f68db38 17
18($op = shift) || die "Usage: relink perlexpr [filenames]\n";
19if (!@ARGV) {
00bf170e 20 @ARGV = <STDIN>;
21 chop(@ARGV);
9f68db38 22}
23for (@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}
00bf170e 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
48relink \- relinks multiple symbolic links
49.SH SYNOPSIS
50.B relink perlexpr [symlinknames]
51.SH DESCRIPTION
52.I Relink
53relinks the symbolic links given according to the rule specified as the
54first argument.
55The argument is a Perl expression which is expected to modify the $_
56string in Perl for at least some of the names specified.
57For each symbolic link named on the command line, the Perl expression
58will be executed on the contents of the symbolic link with that name.
59If a given symbolic link's contents is not modified by the expression,
60it will not be changed.
61If a name given on the command line is not a symbolic link, it will be ignored.
62If no names are given on the command line, names will be read
63via standard input.
64.PP
65For example, to relink all symbolic links in the current directory
66pointing to somewhere in X11R3 so that they point to X11R4, you might say
67.nf
68
69 relink 's/X11R3/X11R4/' *
70
71.fi
72To change all occurences of links in the system from /usr/spool to /var/spool,
73you'd say
74.nf
75
76 find / -type l -print | relink 's#/usr/spool#/var/spool#'
77
78.fi
79.SH ENVIRONMENT
80No environment variables are used.
81.SH FILES
82.SH AUTHOR
83Larry Wall
84.SH "SEE ALSO"
85ln(1)
86.br
87perl(1)
88.SH DIAGNOSTICS
89If you give an invalid Perl expression you'll get a syntax error.
90.SH BUGS
91.ex