#!/usr/bin/perl
#_chmod.pl - Ever wanted to chmod with rws-like strings ?
#_Made on Tuesday Nov 23rd 1999 by Mirko
#_Status : GPL'ed Free Software - visit http://www.gnu.org
#_Syntax : chmod.pl <-rwx-mode> <file>
#_Don't forget the first character of the mode string !
#_(even if this proggy can now work without it ;-)
if ((length(@ARGV[0]) < 9) || (length(@ARGV[1]) == 0)) {
system("grep \\#_ $0 | grep -v grep | cut -c2- | sed 's/_/ /'");
die "Missing parameter. Check the above syntax.\n";
}
$debug = 30;
$cmd = "chmod";
$i = length(@ARGV[0]) - 1;
$coma=" ";
foreach $who ("a", "g", "u") {
foreach $what ("x", "w", "r") {
${$who . $what} = substr(@ARGV0, $i--, 1);
print "\$$who$what = ${$who . $what}\n" if ($debug > 10);
$cmd = ((${$who . $what} cmp "-") != 0) ? $cmd . "$coma$who+${$who . $what}" : $cmd . "$coma$who-$what";
$coma = "," if (($coma cmp " ") == 0);
}
}
$cmd = $cmd . " @ARGV[1]";
print "$cmd\n" if ($debug > 10);
system ("$cmd");