bash string-operator problem

Eric Blake eblake@redhat.com
Thu Feb 21 21:46:00 GMT 2019


On 2/21/19 2:17 PM, Lee wrote:

>>
>> One equal sign ('=') should be used instead of two equal signs ('==').
> 
> The man page for test says you're correct, but just out of curiosity
> -- why do two equal signs work?

Use of [ ... == ... ] is a bash extension. It works in bash, but is not
portable to other /bin/sh (notoriously == fails in dash, and is not
required by POSIX).

Oddly enough, POSIX is considering standardizing a common subset of [[;
in that case, [[ ... = ... ]] is non-portable, and the proposal only
documents [[ ... == ... ]] as being valid.  For more than you ever
wanted to know, read http://austingroupbugs.net/view.php?id=375

-- 
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



More information about the Cygwin mailing list