#!/bin/ksh #New version of chmod envisioned on p. 56. The user can write the 9 #permission bits as the 9 characters familiar from the output of ls -l, #rather than as 3 octal digits. Sample use: instead of # chmod 644 filename1 filename2 filename3 ... #just say # chmod rw-r--r-- filename1 filename2 filename3 ... #or even # chmod rw-r--r filename1 filename2 filename3 ... if [[ $# -lt 2 ]] then echo $0: must have at least two arguments. 1>&2 exit 1 fi octal=$1 shift #Handout 7, p. 6. Now $* will be only the filenames. /bin/chmod `echo $octal | sed ' #If the user typed less than 9 characters, right-pad the string #with dashes until it is 9 characters long. s/$/---------/ s/^\(.........\).*$/\1/ #If s/---/0/g were first, would change rwxr---wx to 7r0wx and get stuck. s/--x/1/g s/-w-/2/g s/-wx/3/g s/r--/4/g s/r-x/5/g s/rw-/6/g s/rwx/7/g s/---/0/g '` $* #Handout 4, pp. 21, 23 for $* if [[ -t 1 ]] #If the standard output is going to screen of terminal, then ls -l $* #give the user some feedback. fi exit 0