On Wed, Apr 04, 2007 at 04:11:56PM +0100, Chris G wrote:
I want to group some logic in a test in a bash script.
I.e. I am trying to write something like:-
if [ this -a (that -o theOther) ]
but bash always complains about 'syntax error'. I have reduced the code to the trivial:-
home$ if [ ( true ) ]; then
but still get the syntax error.
According to the man page for test the format is:-
( EXPRESSION ) EXPRESSION is true
I *think* that is trying to tell me that I can use () to group parts of what is inside the []. However, as I said, it refuses to work as I expected. I have tried all combinations of spaces etc. either side of the () but it still just gives a syntax error.
Is this just a case where the () are punctuation in the man page rather than real () to use in the expression? Or am I doing something obvious wrong? (probably!).
Well, afaik, -a is a file test, so that's probably not what you want...
Also, you don't say if "this", "that" and "theOther" are commands or not... if they are, you probably don't want to be using test to work it out, and something more like...
if ( true && ( false || true ) ); then echo yes; fi
if they're variables, then something more like:
if [ this ] && ( [ that ] || [ theOther ] ); then echo yes; fi
Would be your friend.
Hope that helps.