So I have the following little script and keep wondering..
#!/bin/bash
if [ -d $1 ]; then
echo \'foo\'
else
echo \'bar\'
fi
.. why doe
The reason is plain and simple: The syntax does not match the case in which the -d is recognized as an operator working on a file name. It is just taken as a string, and each non-empty string is true. Only if a second parameter to -d is given, it is recognized as the operator to find out whether a given FILE is a directory.
The same applies to all the other operators like -e, -r, etc.
In your case, use double quotes to avoid running into that "problem":
[ -d "$1" ]