[prev in list] [next in list] [prev in thread] [next in thread] 

List:       majordomo-workers
Subject:    Re: Chown and find
From:       Jim Jagielski <jim () jaguNET ! com>
Date:       1996-10-30 16:48:57
[Download RAW message or body]

Bill Silvert wrote:
> 
> Jerry Peek writes:
> 
> >>>find . -exec chown $USER {} \;
> >>>find . -exec chgrp $GROUP {} \;
> >
> >This is a good substitute for chown -R, I think.  But if the chown
> >fails on some pathname, the chgrp will run, anyway, and might fail
> >too.  If you write the find another way, a failed chown (with a nonzero
> >status) will prevent the chgrp from running on that particular
> >pathname... it also avoids descending the tree twice:
> >
> >      find . -exec chown $USER {} \; -exec $GROUP {} \;
> >
> >There's an implied "-and" between the first and second -exec's.
> >"find" does left-to-right short-circuit evaluation on the expression;
> >and it will quit if it can tell that the expression will be false.
> 
> An alternative would be to create a file called mjchown as part of the
> installation process, so that we could have
> 
> find $MJ_HOME -exec $MJ_HOME/mjchown $USER $GROUP {} \;
> 
> and write mjchown to be as general and bulletproof as desired, using
> exit codes and so on. I'm not sure about the exit codes, but maybe
> 
> #/bin/sh
> if ( chown $1 $3 )
> then chgrp $2 $3
> fi
> 

I had suggested:
    #!/bin/sh
    #
    # Emulate the user:group and user.group 'chown'
    #  for max portability, assume V7 shell, sed and awk
    #			jmj
    #
    Param=`echo $1 | sed 's/[\.:]/ /'`
    shift
    User=`echo $Param | awk '{ print $1 }'`
    Group=`echo $Param | awk '{ print $2 }'`
    if [ "x$Group" = "x" ]; then
	:
    else
	chgrp $Group "$@"
    fi
    chown $User "$@"

B
-- 
#include <std/disclaimer>
=========================
     Jim Jagielski  << jim@jaguNET.com >>   |   "Not the craw... the CRAW!"

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic