perl 3.0 patch #44 patch #42, continued
[p5sagit/p5-mst-13.2.git] / eg / relink
CommitLineData
9f68db38 1#!/usr/bin/perl
00bf170e 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#
9f68db38 11
12($op = shift) || die "Usage: relink perlexpr [filenames]\n";
13if (!@ARGV) {
00bf170e 14 @ARGV = <STDIN>;
15 chop(@ARGV);
9f68db38 16}
17for (@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}
00bf170e 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
42relink \- relinks multiple symbolic links
43.SH SYNOPSIS
44.B relink perlexpr [symlinknames]
45.SH DESCRIPTION
46.I Relink
47relinks the symbolic links given according to the rule specified as the
48first argument.
49The argument is a Perl expression which is expected to modify the $_
50string in Perl for at least some of the names specified.
51For each symbolic link named on the command line, the Perl expression
52will be executed on the contents of the symbolic link with that name.
53If a given symbolic link's contents is not modified by the expression,
54it will not be changed.
55If a name given on the command line is not a symbolic link, it will be ignored.
56If no names are given on the command line, names will be read
57via standard input.
58.PP
59For example, to relink all symbolic links in the current directory
60pointing to somewhere in X11R3 so that they point to X11R4, you might say
61.nf
62
63 relink 's/X11R3/X11R4/' *
64
65.fi
66To change all occurences of links in the system from /usr/spool to /var/spool,
67you'd say
68.nf
69
70 find / -type l -print | relink 's#/usr/spool#/var/spool#'
71
72.fi
73.SH ENVIRONMENT
74No environment variables are used.
75.SH FILES
76.SH AUTHOR
77Larry Wall
78.SH "SEE ALSO"
79ln(1)
80.br
81perl(1)
82.SH DIAGNOSTICS
83If you give an invalid Perl expression you'll get a syntax error.
84.SH BUGS
85.ex