#!/bin/sh # # $TOOLS/mode # # Defines mode environment variable containing the numeric protection of file # $PROG # # Must be called by using the following format: PROG=filespec # . mode # (where filespec is the file specification whose mode is to be determined) # if [ "$PROG" = "" ]; then echo "Usage: PROG=" echo " . mode" exit 2 fi if [ ! -r $PROG ] then echo "Error: Can't find file: $PROG - Aborting...\007" echo "Usage: PROG=" echo " . mode" exit 2 fi mode=`ls -l $PROG | awk ' BEGIN { x = 0 } { if (substr($1, 2, 1) == "r") x = x + 400 if (substr($1, 3, 1) == "w") x = x + 200 if (substr($1, 4, 1) == "x") x = x + 100 if (substr($1, 5, 1) == "r") x = x + 40 if (substr($1, 6, 1) == "w") x = x + 20 if (substr($1, 7, 1) == "x") x = x + 10 if (substr($1, 8, 1) == "r") x = x + 4 if (substr($1, 9, 1) == "w") x = x + 2 if (substr($1, 10, 1) == "x") x = x + 1 } END { print x } '`; export mode