Friendly UMASK wanted

Maarten Litmaath maart at cs.vu.nl
Fri Feb 2 12:32:10 AEST 1990


In article <2069 at syma.sussex.ac.uk>,
	andy at syma.sussex.ac.uk (Andy Clews) writes:
\...
\		umask go-rw

Csh:
	alias	mask    'set tmp="`/full/path/of/mask \!*`"; eval $tmp'

Sh (supporting shell functions):

	mask()
	{
		tmp="`/full/path/of/mask $*`" 
		eval $tmp 
	}

...mask being the following shell script hack (Perl, Randal?).

: This is a shar archive.  Extract with sh, not csh.
: This archive ends with exit, so do not worry about trailing junk.
: --------------------------- cut here --------------------------
PATH=/bin:/usr/bin:/usr/ucb
echo Extracting 'mask'
sed 's/^X//' > 'mask' << '+ END-OF-FILE ''mask'
X#!/bin/sh
X# @(#)mask 1.0 90/02/02 Maarten Litmaath
X# mask g-wx,o=
X# mask -s
X
XUSAGE="
Xname=`basename $0`
Xecho 'Usage: '\$name' mode' >&2
Xecho '   or: '\$name' [-s]' >&2
Xecho 'mode: a symbolic string like \`g-wx,o='\\' >&2
Xecho '  or: the equivalent octal number' >&2
Xecho 'see chmod(1)' >&2
Xexit 1
X"
X
Xcase $# in
X0)
X	echo echo `umask`
X	exit 0
X	;;
X1)
X	;;
X*)
X	eval "$USAGE"
Xesac
X
Xcase $1 in
X-s)
X	set `
X		umask | sed -e 's/^0*//' -e 's/^.$/0&/' -e 's/^..$/0&/' \
X			-e 's/./& /g'
X	`
X	modes_7=
X	modes_6=x
X	modes_5=w
X	modes_4=wx
X	modes_3=r
X	modes_2=rx
X	modes_1=rw
X	modes_0=rwx
X	eval echo echo u=\$modes_$1,g=\$modes_$2,o=\$modes_$3
X	exit 0
Xesac
X
Xexpr x"$1" : 'x.*[^0-9]' > /dev/null || {
X	echo umask "$1"
X	exit 0
X}
X
Xset `
X	echo x"$1" | sed -e 's/.//' -e 's/^[-+=]/a&/' \
X		-e 's/,\\([-+=]\\)/,a\\1/g' \
X		-e 's/[-=],/-rwx,/g' -e 's/[-=]$/-rwx/' \
X		-e 's/+,/+rwx,/g' -e 's/+$/+rwx/' -e 's/./& /g' -e 's/$/,/'
X`
X
Xu_r=r
Xu_w=w
Xu_x=x
Xg_r=r
Xg_w=w
Xg_x=x
Xo_r=r
Xo_w=w
Xo_x=x
X
Xgroups=
Xperms=
X
Xfor i
Xdo
X	case $i in
X	[ugo])
X		groups="$groups $i"
X		;;
X	a)
X		groups="u g o"
X		;;
X	[-+=])
X		op=$i
X		;;
X	[rwx])
X		perms="$perms $i"
X		;;
X	,)
X		for group in $groups
X		do
X			case $op in
X			=)
X				eval ${group}_r=_
X				eval ${group}_w=_
X				eval ${group}_x=_
X			esac
X			for perm in $perms
X			do
X				case $op in
X				-)
X					bit=_
X					;;
X				*)
X					bit=$perm
X				esac
X				eval ${group}_$perm=$bit
X			done
X		done
X		groups=
X		perms=
X		;;
X	*)
X		eval "$USAGE"
X	esac
Xdone
X
X___=7
X__x=6
X_w_=5
X_wx=4
Xr__=3
Xr_x=2
Xrw_=1
Xrwx=0
X
Xeval echo umask 0\${$u_r$u_w$u_x}\${$g_r$g_w$g_x}\${$o_r$o_w$o_x}
+ END-OF-FILE mask
chmod 'u=rwx,g=,o=' 'mask'
set `wc -c 'mask'`
count=$1
case $count in
1555)	:;;
*)	echo 'Bad character count in ''mask' >&2
		echo 'Count should be 1555' >&2
esac
exit 0
--
  What do the following have in common:  access(2), SysV echo, O_NONDELAY?  |
  Maarten Litmaath @ VU Amsterdam:  maart at cs.vu.nl,  uunet!mcsun!botter!maart



More information about the Alt.sources mailing list