1
1
mirror of https://github.com/chubin/cheat.sh.git synced 2024-12-04 03:32:05 +03:00

cleaner chmod if statemnts

This commit is contained in:
Your Name 2020-05-30 23:36:35 -04:00
parent b9d48a3905
commit d87b1f89e5

View File

@ -16,13 +16,13 @@ chmod_calc(){
setgid=' ' setgid=' '
sticky=' ' sticky=' '
# If permission number is given calc string # If permission number is given calc string
if [[ $1 =~ ^-?[0-9]+$ ]] && [ ${#1} -ge 2 ] && [ ${#1} -le 4 ] if [[ $1 =~ ^-?[0-9]+$ && ${#1} -ge 2 && ${#1} -le 4 ]]
then then
p_n=$1 p_n=$1
for (( i=0; i<${#1}; i++ )) for (( i=0; i<${#1}; i++ ))
do do
num=$(echo "obase=2;${1:$i:1}" | bc | xargs printf '%03d') num=$(echo "obase=2;${1:$i:1}" | bc | xargs printf '%03d')
if [ ${#1} -eq 4 ] && [ $i -eq 0 ] if [[ ${#1} -eq 4 && $i -eq 0 ]]
then then
[ ${num:0:1} -eq 1 ] && setuid='X' || setuid=' ' [ ${num:0:1} -eq 1 ] && setuid='X' || setuid=' '
[ ${num:1:1} -eq 1 ] && setgid='X' || setgid=' ' [ ${num:1:1} -eq 1 ] && setgid='X' || setgid=' '
@ -42,7 +42,7 @@ chmod_calc(){
fi fi
done done
# If permission string is given calc number # If permission string is given calc number
elif [ ${#1} -le 9 ] && [ $(( ${#1} % 3 )) -eq 0 ] && [[ $1 =~ ^[r,w,x,s,S,-]+$ ]] elif [[ ${#1} -le 9 && $(( ${#1} % 3 )) -eq 0 && $1 =~ ^[r,w,x,s,S,-]+$ ]]
then then
p_s=$1 p_s=$1
[[ ${p_s,,} =~ 's' ]] && p_n+="1" || p_n+="0" [[ ${p_s,,} =~ 's' ]] && p_n+="1" || p_n+="0"