NetBSD-Bugs archive

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

Re: bin/44733: [PATCH] Have test/[ accept "==" as a synonym for "="



Regarding the proposed patch to implement "==" as a synonym for "==" in test/[:

Valeriy E. Ushakov:
>  Why would we want to?  Compatibility with bash?

Not primarily, though that has some benefit.  There are several reasons to 
implement "==" as a synonym for "=".

The underlying reason is that "=" is also used for shell variable assignment.  
Using the SAME spelling for "is-equal-to" and "assignment" is unfortunate, and 
is something that many languages avoid.  Many languages that use "=" for 
assignment use a SEPARATE "==" operator for comparison; this includes C, C++, 
Java, C#, Python, and Perl.  Many languages (like Pascal) that use "=" for 
comparison use another spelling like ":=" for assignment, again, to keep their 
spellings separate (these languages can often disambiguate from context... but 
they intentionally don't).  It is odd that the shell, unlike all these 
languages, conflates their spellings.  It's too late to get rid of "=" for 
comparison, but it's easy to add "==" as a synonym, which is what is proposed.  
So adding this ability (1) clarifies whether assignment or comparison is being 
used, and (2) improves consistency between shell and other languages that use 
"=" for assignment.

This is NOT a bash-unique extension, so I argue that it is NOT a bashism.  LOTS 
of shells ALREADY implement this.  This is implemented in not only bash, but 
also ksh, busybox ash, FreeBSD-current's /bin/sh and /bin/test (see 
http://svn.freebsd.org/base/head/bin/test/test.c), and OpenBSD's /bin/sh. At 
least.  *ALL* of these implementations agree that "==" is a synonym for "=", so 
there's no question about "different semantics so which one should we 
implement?".

This extension is already in wide use in shell scripts, even ones not written 
for bash.  Several NetBSD bugs have been filed because NetBSD can't handle 
"==".  Can you change the scripts?  Sure.  But why not add the facility to 
NetBSD instead?  Nothing in the POSIX specification forbids it, it's trivial to 
add, and it'd make it easier to port programs to NetBSD.

>  But non-trivial bash
>  scripts quite often have other bashisms in them, so anyone who depends
>  on running bash scripts is probably better served by just installing
>  bash package.

As noted above, a shell script originally written with a shell OTHER than bash, 
such as OpenBSD's /bin/sh or Busybox /bin/sh, can use "==", and these shells 
don't support many extensions.  Busybox focuses on being as tiny as possible, 
and even they found it useful to support "==".

--- David A. Wheeler


Home | Main Index | Thread Index | Old Index