This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: bash string-operator problem
- From: john doe <johndoe65534 at mail dot com>
- To: cygwin at cygwin dot com
- Date: Thu, 21 Feb 2019 18:39:56 +0100
- Subject: Re: bash string-operator problem
- References: <d846545ebaa5469d90f01f84e4f48c3d@vsrv060ex01.ssd.fsi.com> <CAD8GWsvqXdG-2YvmVAqW=jkZ_ejHGOj=LCemjoqkF08Vy7i=Fw@mail.gmail.com>
On 2/21/2019 5:18 PM, Lee wrote:
> On 2/21/19, 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 <----- needs spaces around the !=
>> echo -e "not identical"
>> fi
>> if [ $A==$B ]; then <------ needs spaces around the ==
>> echo -e "identical"
>> fi
>> exit 0
>>
>> Running this script gives
>> not identical
>> identical
>>
>> Both tests are true.
>
> because you're testing "A==B"
> you need to give 3 parameters "A" "==" "B"
>
> $ cat x
> #!/bin/bash
> A="A"
> B="A"
> if [ $A != $B ]; then
> echo "not identical"
> fi
> if [ $A == $B ]; then
> echo "identical"
> fi
> if [ A!=B ]; then
> echo "not identical"
> fi
> if [ A==B ]; then
> echo "identical"
> fi
>
One equal sign ('=') should be used instead of two equal signs ('==').
--
John Doe
--
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