YA resync with mainstem, including VMS patches from others
[p5sagit/p5-mst-13.2.git] / eg / g / gsh
index 50ce1f7..4bc5d87 100644 (file)
--- a/eg/g/gsh
+++ b/eg/g/gsh
@@ -1,6 +1,6 @@
-#!/bin/perl
+#! /usr/bin/perl
 
-# $Header: gsh,v 2.0 88/06/05 00:17:20 root Exp $
+# $RCSfile: gsh,v $$Revision: 4.1 $$Date: 92/08/07 17:20:20 $
 
 # Do rsh globally--see man page
 
@@ -8,11 +8,12 @@ $SIG{'QUIT'} = 'quit';                        # install signal handler for SIGQUIT
 
 sub getswitches {
     while ($ARGV[0] =~ /^-/) {         # parse switches
-       $ARGV[0] =~ /^-h/ && ($showhost++,$silent++,shift,next);
-       $ARGV[0] =~ /^-s/ && ($silent++,shift,next);
-       $ARGV[0] =~ /^-d/ && ($dodist++,shift,next);
-       $ARGV[0] =~ /^-n/ && ($n=' -n',shift,next);
-       $ARGV[0] =~ /^-l/ && ($l=' -l ' . $ARGV[1],shift,shift,next);
+       $ARGV[0] =~ /^-h/ && ($showhost++,$silent++,shift(@ARGV),next);
+       $ARGV[0] =~ /^-s/ && ($silent++,shift(@ARGV),next);
+       $ARGV[0] =~ /^-d/ && ($dodist++,shift(@ARGV),next);
+       $ARGV[0] =~ /^-n/ && ($n=' -n',shift(@ARGV),next);
+       $ARGV[0] =~ /^-l/ && ($l=' -l ' . $ARGV[1],shift(@ARGV),shift(@ARGV),
+                               next);
        last;
     }
 }
@@ -74,19 +75,19 @@ line: while (<>) {          # for each line of ghosts
     if ($wanted > 0) {
        print "rsh $host$l$n '$cmd'\n" unless $silent;
        $SIG{'INT'} = 'DEFAULT';
-       if (open(pipe,"rsh $host$l$n '$cmd'$dist 2>&1|")) {     # start an rsh
+       if (open(PIPE,"rsh $host$l$n '$cmd'$dist 2>&1|")) {     # start an rsh
            $SIG{'INT'} = 'cont';
-           for ($iter=0; <pipe>; $iter++) {
+           for ($iter=0; <PIPE>; $iter++) {
                unless ($iter) {
                    $remainder .= "$host+"
                        if /Connection timed out|Permission denied/;
                }
                print $showhost,$_;
            }
-           close(pipe);
+           close(PIPE);
        } else {
+           print "(Can't execute rsh: $!)\n";
            $SIG{'INT'} = 'cont';
-           print "(Can't execute rsh.)\n";
        }
     }
 }
@@ -95,7 +96,7 @@ unlink "/tmp/gsh$$" if $dodist;
 
 if ($remainder) {
     chop($remainder);
-    open(grem,">.grem") || (printf stderr "Can't make a .grem file\n");
+    open(grem,">.grem") || (printf stderr "Can't make a .grem file: $!\n");
     print grem 'rem=', $remainder, "\n";
     close(grem);
     print 'rem=', $remainder, "\n";