On Sep 12, 2007, at 2:56 AM, Bob Proulx wrote:
The [ is a shell builtin, not a shell metacharacter. Shell metacharacters do not need to be separated by whitespace but the test program needs to be apart or it won't be parsed right. That is why you are seeing "[-d" not found. It is not a parenthesis as in some programming languages. The [ is a synonym for the "test" operator. It is a command like grep, sed, awk, etc.
Being that I'm not a bash (or any other shell for that matter) guru, is there any reason that parsing occurs this way? Why is it not more like other programming languages?
[ -d /tmp ] && echo /tmp is a dir Do it this way. if [ -d "$i" ] Note that you should quote the argument to protect against whitespace there.
Thanks, that worked perfectly!