[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -d option not working. . .?

From: Michael Williams
Subject: Re: -d option not working. . .?
Date: Wed, 12 Sep 2007 06:06:21 -0400

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

Thanks, that worked perfectly!

reply via email to

[Prev in Thread] Current Thread [Next in Thread]