X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-0.8 required=5.0 tests=AWL,BAYES_00,DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,SPF_HELO_PASS,T_RP_MATCHES_RCVD,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org To: cygwin AT cygwin DOT com From: Oleksandr Gavenko Subject: Re: 'test' utility behavior question. Date: Mon, 30 Aug 2010 20:46:58 +0300 Lines: 34 Message-ID: References: <4C7BEB07 DOT 9010908 AT redhat DOT com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100802 Thunderbird/3.1.2 In-Reply-To: <4C7BEB07.9010908@redhat.com> X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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