let me ask cause i´ve been trying for some days and i don´t know if it is possible my idea.
I have the following text in a file1:
aaa common-criteria policy POLICY1
min-length 8
max-length 16
numeric-count 1
upper-case 3
lower-case 2
char-changes 4
!
and the following text in a file2:
aaa common-criteria policy POLICY2
min-length 1
max-length 127
char-changes 4
!
and i would like to check all values in both files are correct, based on the threshold in my policies. So i have created two arrays with thresholds in order to compare each value with those from each file
declare -a COM=("min-length" "max-length" "upper-case" "lower-case" "numeric-count")
declare -a OPE=("-ge" "-le" "-ge" "-ge" "-ge")
declare -a VAL=("8" "16" "1" "1" "1")
And I've created loop to check each value from file against value in VAL(i)
for ((i=0; i<${#COM[@]}; i++)); do
THRESHOLD=$(grep ${COM[$i]} FILE | awk -F " " '{print $2}') --> to get value VAL(i) for each comand COM(i)
if [[ $THRESHOLD -ge "${VAL[$i]}" ]]; then echo "OK"; else echo "KO"; fi
done
Next step should be to change "-ge" to OPE(i) in if condition, to allow each command be analyzed in the right way, as "max-length" value should be less than threshold. if i change "-ge" to ${OPE[$i]} if [[ "$THRESHOLD" "${OPE[$i]}" "${VAL[$i]}" ]] the process fails "conditional binary operator expected syntax error near `${OPE[$i]}'
Do you know if "if" condition has this flexibility syntaxis? Thanks!