[NTLUG:Discuss] Using test with multiple conditions
Eric Schnoebelen
eric at cirr.com
Fri Mar 10 08:23:14 CST 2017
Leroy Tennison writes:
- I haven't been able to determine where the problem is, I'm either
- getting bash errors or a uniform result when it should be changing.
- What I'm trying to get is a zero return code when either test returns a
- zero return code or a non-zero return code otherwise. The test in this
- case is "a2query -qc <configuration name>'. This apache program, with
- -qc, is supposed to return zero if the configuration name is found and 1
- otherwise. What I've tried so far is:
-
- test $(a2query -qc one) -o $(a2query -qc serve-cgi-bin);echo $? $? is
- zero (correct since serve-cgi-bin is found)
[...]
I think you're trying too hard. Since a2query is a program, you
don't need to use test to evaluate its return value. Shell
evaluation should be sufficent.
eg:
a2query -qc one || a2query -qc serve-cgi-bin
If you need to wrap it in a conditional:
if ( a2query -qc one || a2query -qc serve-cgi-bin); then
:
fi
test(1) is more useful for testing for file existance, or if a
variable is set, or the value of a variable (or program
results.)
I hope this helps,
Eric
--
Eric Schnoebelen eric at cirr.com http://www.cirr.com
... software is largely a service industry operating under the persistent
but unfounded delusion that it is a manufacturing industry. -- Eric S. Raymond
More information about the Discuss
mailing list