Chek if a file exists in Ubuntu and Cent OS using shell script

I have tried few examples in the internet but all of them are different and none worked. I need to check if a file exists in a directory if it does not then exit . here is what I have for now

$filename ="/usr/local/net/var/lib/directoryservice/sync.disable"
if [-e $filename ];
then
echo "The file exists"
else
echo "Does not exist"
fi

This gives me error saying the ="/usr/local/net/var/lib/directoryservice/sync.disable" is not a directory or file and -e option does not exist. I need to be working on ubuntu and centos.

Any help will be appreciated.

Thank you.

You need a space between the opening square bracket and the -e. The opening square bracket -- believe it or not -- is the name of a command (also known as test) and like other commands, it needs to be its own space-separated token.

Also, you need to drop the dollar sign when assigning to a variable, and not have any spaces between the variable name, the equals sign, and the value.

Oh woow its unbelievable that such a small mistake would cost so much time. Thanks a lot it works fine now.