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 that
[ -d ] && echo y
produces y
is that the shell interprets it as a string in the test
command and evaluates it to true. Even saying:
[ a ] && echo y
would produce y
. Quoting from help test
:
string True if string is not the null string.
That is why quoting variables is recommended. Saying:
[ -d "$1" ] && echo y
should not produce y
when called without arguments.