I canβt let my life determine the correct regular expression for this.
I am looking for a regular expression to match the actual numerical representation of permissions on Linux files (e.g. 740 for all-read-none, 777 for all-all-all). So far I have tried the following:
strtotest=740 echo "$strtotest" | grep -q "[(0|1|2|3|4|5|7){3}]" if [ $? -eq 0 ]; then echo "found it" fi
The problem with the above is that the regular expression matches anything with 1-5 or 7 in it, regardless of any other characters. For example, if strtotest needed to be changed to 709 , the condition would be true. I also tried [0|1|2|3|4|5|7{3}] and [(0|1|2|3|4|5|7{3})] , but they do not work either.
Am I using regex or am I missing something related to grep ?
Sho kei
source share