-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!

0

1 Answer 1

-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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
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
Ah, I am sorry for my mistake.. but I still suggest to separate the expression idea.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.