From 1abecaa0c9febfcf48b2e8b3c0d4e9585b3a8ef0 Mon Sep 17 00:00:00 2001 From: aryamagarwal Date: Fri, 15 Mar 2024 11:07:36 +0530 Subject: [PATCH] Adding Perms script. Solving #6 --- scripts/perms | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/scripts/perms b/scripts/perms index b683156..5649412 100755 --- a/scripts/perms +++ b/scripts/perms @@ -6,4 +6,37 @@ # $ perms weather ../README.md # 775 weather # 664 ../README.md +func () +{ + for arg in "${@}" + do + op=$(ls -l $arg) + sum=0 + result="" + for (( i=1; i <= 9; i++ )) + do + if [ $(($i%3)) -eq 0 ] + then + result="${result}${sum}" + sum=0 + fi + ch=${op:$i:1} + if [ $ch == 'r' ] + then + sum=$(($sum+4)) + fi + if [ $ch == 'w' ] + then + sum=$(($sum+2)) + fi + if [ $ch == 'x' ] + then + sum=$(($sum+1)) + fi + done + echo "${result} ${arg}" + done +} + +func "${@}"