[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: -d option not working. . .?
From: |
Bob Proulx |
Subject: |
Re: -d option not working. . .? |
Date: |
Wed, 12 Sep 2007 00:56:02 -0600 |
User-agent: |
Mutt/1.5.9i |
Michael Williams wrote:
> if [-d $i]
That is not the correct syntax. 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.
[ -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.
Bob