I'm trying to work out the correct syntax to state a relatively simple if test.
What I want to say is : if a is true or (b is true and c is true) then do something.
I can't seem to get the syntax correct using a standard [ ] notation.
if [ $(some executable) -o ( $(some executable) -a $(some executable ) ]; then
Also, man bash says: ( _expression_ ) Returns the value of _expression_. This may be used to override the normal precedence of operators.
No matter what I try I can't seem to get the syntax correct to use ( ) as shown above.
Below is one of the numerous versions I've tried with no success. To aid in your understanding, templateMachine contains either an IP address or short hostname. I'm trying to figure out if this represents an item in an /etc/hosts file.
I've tried breaking the test up into multiple tests (as shown), as a single [ ] test using ( ) to group the -a , and numerous other arrangements, and none work. I either get bash syntax errors or the line of code simply doesn't do what I want.
if [ $(echo "${templateMachine}"|egrep -q '\.') -a $(grep -q "${templateMachine}" /etc/hosts|grep -q $(hostname -s)) ] || [ "${templateMachine}" == $(hostname -s) ]; then
Lastly, I've read up on [[ ]] numerous times in man bash and I can't quite wrap my head around it. Can someone point at an alternate explanation on the features and benefits of using [ ] vs [[ ]] ? -- Bill Gradwohl