So I'm writing a script that has to check if a file exists or not before executing. I have the following code:
if [[ \( -d "DIR2" \) != true ]];
then
echo "nonexistent dir"
exit 1
elif [[ \( -d "DIR1" || -f "DIR1" \) != true ]];
then
echo "nonexistent dir or file"
exit 1
fi
I seem to be doing something wrong with the brackets since I get the following:
./syncdir.sh: line 11: conditional binary operator expected
./syncdir.sh: line 11: syntax error near `-d'
./syncdir.sh: line 11: `if [[ \( -d "DIR2" \) != true ]];'
I find it odd that bash is expecting a binary operator isnt '!=' one?
Can someone please tell me what I am doing wrong and why?
I really get confused with the brackets, I still haven't got the hang of it.