This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: 'test' utility behavior question.
- From: Eric Blake <eblake at redhat dot com>
- To: cygwin at cygwin dot com
- Date: Mon, 30 Aug 2010 11:31:51 -0600
- Subject: Re: 'test' utility behavior question.
- References: <i5gpmp$ur$1@dough.gmane.org>
On 08/30/2010 11:27 AM, Oleksandr Gavenko wrote:
$ /bin/test -d && echo ok
ok
$ /bin/test -d '' && echo ok || echo must_be_error
must_be_error
Both of these results match POSIX. Remember, POSIX describes different
behaviors for one argument than for two arguments (for the one-argument
case, the string "-d" is non-empty, so the result must be 0; for the
two-argument case, the string "-d" is a unary operator, and there is no
directory named '').
if [ -d $dir ]; then
The bug is in your script. You forgot to use quoting or a bashism.
Either of these fixes will correct your script (although the latter
requires bash):
if [ -d "$dir" ]; then
if [[ -d $dir ]]; then
This is not cygwin-specific.
--
Eric Blake eblake@redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple