Is [t]csh's `filetest` builtin viable here?

Relurking,
Ben

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED]] On Behalf Of 
> Giorgos Keramidas
> Sent: Saturday, May 18, 2002 10:29 PM
> To: [EMAIL PROTECTED]
> Subject: Re: mergemaster(8) broken -- uses Perl
> 
> 
> On 2002-05-18 11:54, David O'Brien wrote:
> > Anyone got a patch?
> 
> Part of the problems I had when I tried to replace perl in
> mergemaster.sh with something `native' was that the perl code uses
> stat(2) to obtain the permission bits of a directory/file and I can't
> think of a way to do this with tools in the base system without
> resorting to ugly awk scripts that parse and translate ls(1) output.
> 
> Any ideas?  I am not really sure I like something like:
> 
>       % /bin/ls -ld /tmp | sed -e 's/[[:space:]].*$//' |\
>       awk -v mode=0 '{
>               if (match($0, "^.r........")) { mode += 00400; }
>               if (match($0, "^..w.......")) { mode += 00200; }
>               if (match($0, "^...S......")) { mode += 04000; }
>               if (match($0, "^...s......")) { mode += 04100; }
>               if (match($0, "^...x......")) { mode += 00100; }
>               if (match($0, "^....r.....")) { mode += 00040; }
>               if (match($0, "^.....w....")) { mode += 00020; }
>               if (match($0, "^......S...")) { mode += 02000; }
>               if (match($0, "^......s...")) { mode += 02010; }
>               if (match($0, "^......x...")) { mode += 00010; }
>               if (match($0, "^.......r..")) { mode += 00004; }
>               if (match($0, "^........w.")) { mode += 00002; }
>               if (match($0, "^.........T")) { mode += 01000; }
>               if (match($0, "^.........t")) { mode += 01001; }
>               if (match($0, "^.........x")) { mode += 00001; }
>       }
>       END { printf "0%o\n", mode; }'
> 
> [ The above should print in stdout just 01777 as a number. ]
> 
> It seems to work, but it's a bit ugly for my taste.  Plus it will
> break if the permission bits ever change representation (although this
> is unlikely to happen any time real soon).
> 
> Does anyone know of any other (possibly more elegant way) of reading
> the numeric value of the permission bits for a file?
> 
> -- 
> Giorgos Keramidas    - http://www.FreeBSD.org
> [EMAIL PROTECTED] - The Power to Serve
> 
> To Unsubscribe: send mail to [EMAIL PROTECTED]
> with "unsubscribe freebsd-current" in the body of the message
> 
> 
> 



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to