-1

I am trying to write an expression using multiple logical operators and shell script as below

if [ [a != b] && [ -d "/path/to/directory"] || [a = b] && [ ! -d "/path/to/directory"] ] ; then execute some steps.

When I run this code, I get syntax error in conditional operator ']'. I tried different ways of having brackers, but could not get it to work. Can someone please help. Many thanks!

chepner
  • 497,756
  • 71
  • 530
  • 681

1 Answers1

-1

You could seperate the condition expression and keep the value in variant, like this to avoid the unpaired parenthesis problem:

CON_1=((a != b) && [ -d "/path/to/directory"])
CON_2=((a == b) && [ ! -d "/path/to/directory"])
if CON_1 || CON_2
then
  # execute some steps
fi

Or try using eclipse plugin ShellEd for the alternative way.

EDIT Change the syntax to be shell. I assumed [] in this context is the logical test operation. Any one please suggest whether it is correct.

Pranithan T.
  • 323
  • 1
  • 6
  • 14
  • I have just copied the `[ -d "/path/to/directory"]` to insert to the variable but I do not know neither what does it mean nor it is right syntax. – Pranithan T. Feb 12 '14 at 04:18
  • Uh - judging from the use of forward-slashes in paths, I'm assuming this is a Unix shell question. But your answer looks like it is for some Windows shell – Digital Trauma Feb 12 '14 at 04:47
  • Ah, I am sorry for my mistake.. but I still suggest to separate the expression idea. – Pranithan T. Feb 12 '14 at 05:11