'How to raise error in bash if a dir does not match certain permissions?

How can I raise an error in bash if a directory at some path does not match the below permissions?

u=rwX,g=rwX,o=rwX


Solution 1:[1]

you can try to use stat command

# /bin/bash

FILENAME=$1
PERM=$(stat --format "%A" $FILENAME)
echo $FILENAME $PERM

u=${PERM:1:3}
g=${PERM:4:3}
o=${PERM:7:3}

echo $u $g $o

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Splinter1984