Xref: utzoo comp.unix.questions:26048 comp.lang.perl:2534 Path: utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!wuarchive!swbatl!texbell!moxie!texsun!convex!convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.unix.questions,comp.lang.perl Subject: Re: Cloning File Protection? Keywords: stat(2) chmod(1) Message-ID: <106915@convex.convex.com> Date: 6 Oct 90 22:10:49 GMT References: <277@talarian.UUCP> Sender: usenet@convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Followup-To: comp.lang.perl Organization: CONVEX Software Development, Richardson, TX Lines: 35 In article <277@talarian.UUCP> scott@talarian.UUCP (Scott Weitzenkamp) writes: > I am trying to write a shell script (either in sh or csh on SunOS 4.0.3) >that can clone the file protection from one file to another. I'd like >to do something like this: > > chmod `get_protection old_file_name` new_file_name [Solution in C deleted.] > I have a feeling this is probably easy to do in Perl, but I not > really interested in a Perl solution because I cannot guarantee that > our customers will have Perl (I suppose I could put Perl on our > product tape, though). You're right -- it *is* easy in perl. Error checking aside, this should do the trick: perl -e 'chmod(((stat(shift))[2] & 0777), @ARGV)' f0 f1 f2 f3 ... This copies f0's perms to the rest of the list, although it doesn't propagate set[ug]id or sticky bits -- use 07777 for that behavior. How many times will you need to cook up another solution in C because your customers don't have perl? I know that this is just one little thing, but after running into dozens of such little things, I realized I was making my own life unnecessarily difficult because of that very line of thinking, so I got perl added to my company's standard utilities tape. I suggest you try to do the same. Just out of curiosity, what other companies supply perl? --tom -- "UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." [Doug Gwyn]