Problem with If statement

Hi All,

I am writing an if statement to check multiple conditions, but when I try to execute the script it is breaking at the point of if statement by showing the issue below.

Code I am using is given below.

if [ "$run" -eq "1" ] -a [ [ -f /tmp/start.Lck || -f /tmp/stop.Lck ] ]
        then
....

else
...

fi

I am not understanding what is the issue here.

Hi, in bash, try:

if [[ $run == 1 && ( -f /tmp/start.Lck || -f /tmp/stop.Lck ) ]]

There should be no space between the double brackets.

2 Likes

The problem is that you use -a outside the brackets. The -a and -o operators belong to the test/ command and can't be used outside. Then on the right side you use the || inside the brackets but the test/ command doesn't understand || but only -o. Outside the use && instead of -a.

This works for me here:

#!/bin/bash
run=1

if [ "$run" -eq "1" ] && [ -f ~/.bashrc -o -f ~/.vimrc ]
then
   echo bingo
fi
1 Like

Thanks All.. Both the code works for me