Is there any method without a loop to check whether all members of the following arrays are equal to true
?
found1=(true true true true);
found2=(true false true true);
You can use the [[ ]]
operator. Here is a function based solution:
check_true() {
[[ "${*}" =~ ^(true )*true$ ]]
return
}
You can use it in this way:
$ found1=(true true true true)
$ found2=(true false true true)
$ check_true ${found1[*]} && echo OK
OK
$ check_true ${found2[*]} && echo OK
OK will be displayed as a result if the condition satisfies
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With