home *** CD-ROM | disk | FTP | other *** search
/ ftp.muug.mb.ca / 2014.06.ftp.muug.mb.ca.tar / ftp.muug.mb.ca / pub / src / perl / eg / relink < prev    next >
Text File  |  1992-04-11  |  2KB  |  89 lines

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