Swapped around chm.sh arguments

This commit is contained in:
Chris Stuurman 2025-02-20 22:28:49 +02:00
parent 433589b86b
commit e50eba80c7

22
chm.sh
View File

@ -6,20 +6,20 @@ ALIASNAME="chm"
_help() { _help() {
echo -n "chm: performs chmod recursively on specified folder with specified values for folder and files. Executable permissions will be set for all folders\n\n" echo -n "chm: performs chmod recursively on specified folder with specified values for folder and files. Executable permissions will be set for all folders\n\n"
echo "Usage: $SCRIPTNAME <folder> <octalvalue> echo "Usage: $SCRIPTNAME <octalvalue> <folder>
or: $ALIASNAME <folder> <octalvalue> or: $ALIASNAME <octalvalue> <folder>
folder : this is the folder on which to execute the command
octalvalue : this is the FILE permissions to be set in the specified folder and its subfolders. Use the same octal value you would use as a chmod argument octalvalue : this is the FILE permissions to be set in the specified folder and its subfolders. Use the same octal value you would use as a chmod argument
folder : this is the folder on which to execute the command
Example: Example:
$SCRIPTNAME ./testfolder 664 ; this will set testfolder and its subfolders to 775 and files in those subfolders to 664 $SCRIPTNAME 664 ./testfolder ; this will set testfolder and its subfolders to 775 and files in those subfolders to 664
$SCRIPTNAME ./testfolder 764 ; this will set testfolder and its subfolders to 775 and files in those subfolders to 764 $SCRIPTNAME 764 ./testfolder ; this will set testfolder and its subfolders to 775 and files in those subfolders to 764
" "
} }
_process() { _process() {
folder=$1 folder=$2
declare -i val=$2 declare -i val=$1
declare -i rwmask=8#111 declare -i rwmask=8#111
declare -i dirval=$val\|$rwmask declare -i dirval=$val\|$rwmask
filevalstr=$(printf "%03o" $val) filevalstr=$(printf "%03o" $val)
@ -38,12 +38,12 @@ main() {
fi fi
declare -i modval=0 declare -i modval=0
{ # try { # try
let modval=8#$2 && let modval=8#$1 &&
_process "$1" $modval _process $modval "$2"
} || { # catch } || { # catch
echo 'ERROR: Check if second argument is a proper octal value!' echo 'ERROR: Check if the first argument is a proper octal value!'
echo 'If not, fix the value and try again.' echo 'If not, fix the value and try again.'
} }
} }
main "$@" main "$@"