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