X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:subject:to:references:from:message-id:date
	:mime-version:in-reply-to:content-type
	:content-transfer-encoding; q=dns; s=default; b=Dh5dURKmxN/qTt6I
	D+j1Dse9HiF+wy4wNeHwO5YzPT1c3/8E10tbnWvauQwzEZ0OBWXpbwYHAYz311bP
	p7Mmlfawz3edjxD/gsre2GdGhE/P+zgBIfHi1vOlN+d+lzhq2TWThH2dwFy8KFPd
	KynXgVDvyq95/K5KQn4CbNkuHrQ=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:subject:to:references:from:message-id:date
	:mime-version:in-reply-to:content-type
	:content-transfer-encoding; s=default; bh=x853XRh9Rzp7wlttAeICHA
	SS1co=; b=vhVQ1V82fesV5T2BuILrubb9b1cRt8O/rTocp8rGA0nIrNBcdEiV0L
	o1hrW9OJMxXLNnTEZD0RL8dHFkk+/va0rfs9Q+MzFDeZqpaaNTOvW+ZyP3Lt5ta2
	iE0Xiho3iAr74u0Si3RhpDWAwF8OfMK1saHX091badGuaFESfedEU=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS autolearn=no version=3.3.2 spammy=A, a
X-HELO: mx1.redhat.com
Subject: Re: bash string-operator problem
To: cygwin@cygwin.com
References: <d846545ebaa5469d90f01f84e4f48c3d@vsrv060ex01.ssd.fsi.com>
From: Eric Blake <eblake@redhat.com>
Message-ID: <2d0a723d-05e8-84e8-8739-e461e6508e79@redhat.com>
Date: Thu, 21 Feb 2019 10:10:02 -0600
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0
MIME-Version: 1.0
In-Reply-To: <d846545ebaa5469d90f01f84e4f48c3d@vsrv060ex01.ssd.fsi.com>
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-IsSubscribed: yes

On 2/21/19 10:00 AM, Rockefeller, Harry wrote:
> CYGWIN_NT-6.1 HARRYR-PC 3.0.0(0.336/5/3) 2019-02-16 13:21 x86_64 Cygwin
> GNU bash, version 4.4.12(3)-release (x86_64-unknown-cygwin)
> 
> #!/bin/bash
> A="A"
> B="A"
> if [ $A!=$B ]; then
>     echo -e "not identical"
> fi
> if [ $A==$B ]; then
>     echo -e "identical"
> fi
> exit 0
> 
> Running this script gives
> not identical
> identical
> 
> Both tests are true.

Well, yeah, but it's not a bug in bash, but in your script. Whitespace
for argument separation is essential in [.  You've provided exactly one
argument, and in one-argument mode, you are testing for non-empty
strings.  Since both strings "A!=B" and "A==B" are non-empty strings,
the if clause is taken both times.  You meant to provide three
arguments, and with proper quoting, and using the portable spelling of
equality (if you want to port your script to more than just bash):

[ "$A" != "$B" ]
[ "$A" = "$B" ]

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | 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

