'test' utility behavior question.
$ /bin/test -d && echo ok ok $ /bin/test -d '' && echo ok || echo must_be_error must_be_error POSIX require argument for -d, so behavior implementation depend. I can not check another 'test' implementation now. For me get error is more convenient, because this not break this code if $dir not defined: if [ -d $dir ]; then do-good-job; else info-user-about-missing-dir; fi To resolve upper code I rewrite condition in POSIX compatible form: [ -d "$dir" ] -- Best regards! -- 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
Re: 'test' utility behavior question.
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 ebl...@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
Re: 'test' utility behavior question.
On 2010-08-30 20:31, Eric Blake wrote: 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. You right! Sorry, I miss this when read POSIX: 1 argument: Exit true (0) if $1 is not null; otherwise, exit false. -- Best regards! -- 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