Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!tut.cis.ohio-state.edu!bloom-beacon!husc6!bu-cs!bzs From: bzs@bu-cs.BU.EDU (Barry Shein) Newsgroups: alt.sources Subject: Re: chmod args (was Re: Need a "watching" program) Message-ID: <32248@bu-cs.BU.EDU> Date: 3 Jun 89 19:25:03 GMT References: <8923@csli.Stanford.EDU> <11680@s.ms.uky.edu> <8928@csli.Stanford.EDU> <12743@ihlpy.ATT.COM> <1953@ur-cc.UUCP> <2126@amelia.nas.nasa.gov> <8605@chinet.chi.il.us> <1738@auspex.auspex.com> Distribution: usa Organization: Boston U. Comp. Sci. Lines: 72 In-reply-to: guy@auspex.auspex.com's message of 3 Jun 89 00:22:33 GMT Many years ago I wrote a simple shell script for new users "setfile" which took either "private" or "public" and a list of one or more file or dir names. It then set the files to reasonable values (private=user only, public=everyone could read and/or execute, only user write in all cases.) So: setpriv public a b c setpriv private x y z Seemed to eliminate a lot of errors. The only tricky part of the script is propagating the execute bit rationally. Also that some shell tests do "the wrong thing" for root, but root shouldn't use the script (but of course it happened, yielding odd results.) Of course, if they want more control they learn chmod. I've attached the source, ugh, it's in csh, well, it was a long time ago...It was meant to be very simple, rather than posting bugs or fixes (particularly to me) I'd suggest just looking at it as an example (or enough sources to justify this note :-) #!/bin/csh # # Simplified chmod script # # setfile [public|private] files.... # if($#argv == 0) goto usage # # The obscure problem here is that if(-x file) # always returns true for root. # if(`whoami` == root) then echo "Doesn't work correctly for root, sorry -- use chmod" exit(0) endif if($argv[1] == 'private') goto private if($argv[1] == 'public') goto public if($argv[1] == 'execute') goto execute goto usage private: shift foreach f ($*) set perm=600 if(-x $f) set perm=700 chmod $perm $f end exit(0) public: shift foreach f ($*) set perm=644 if(-x $f) set perm=755 chmod $perm $f end exit(0) execute: shift foreach f ($*) chmod u+x $f end exit(0) usage: echo "Usage: " $0 "[private|public|execute]" "file[s]" exit(1) -- -Barry Shein Software Tool & Die, Purveyors to the Trade 1330 Beacon Street, Brookline, MA 02146, (617) 739-0202