chmod args (was Re: Need a "watching" program)

Barry Shein bzs at bu-cs.BU.EDU
Sun Jun 4 05:25:03 AEST 1989


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



More information about the Alt.sources mailing list