bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: BUG??


From: Charles Daffern
Subject: Re: BUG??
Date: Thu, 29 Dec 2016 01:28:36 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0

On 29/12/16 01:09, Peter & Kelly Passchier wrote:
> Is this a bug? These both output "q=1"
>
> q=1
> [[ ((q==1)) ]] && echo q=1
>
> q=0
> [[ ((q==1)) ]] && echo q=1
>
>
This looks like an incorrect use of [[/((. The correct phrasing would be:


q=1

((q==1)) && echo q=1

q=0

((q==1)) && echo q=1


By wrapping it in the [[ operator, instead of running ((...)) as a
command, you're testing whether it is a string of nonzero length (and it
always is, since you have it typed right there). The ((...)) operator
alone is sufficient to make the test you want to make.


It could also be phrased as:


q=1

[[ $q -eq 1 ]] && echo q=1

q=0

[[ $q -eq 1 ]] && echo q=1


In the bash man page, under the SHELL GRAMMAR section is a description
of the [[ operator, which should shed some further light on why this
behaves as it does.


Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]