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



The following reply was made to PR bin/44733; it has been noted by GNATS.

From: "David A. Wheeler" <dwheeler%dwheeler.com@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: netbsd-bugs%netbsd.org@localhost, gnats-admin%netbsd.org@localhost, 
uwe%stderr.spb.ru@localhost,
 jruohonen%iki.fi@localhost, kre%munnari.OZ.AU@localhost, 
holland-bugs%netbsd.org@localhost
Subject: Re: bin/44733: [PATCH] Have test/[ accept "==" as a synonym for "="
Date: Thu, 17 Mar 2011 14:41:50 -0400 (EDT)

 Regarding the proposed patch to implement "=3D=3D" as a synonym for "=3D=3D=
 " 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 "=3D=3D" as a synonym for "=3D".
 
 The underlying reason is that "=3D" is also used for shell variable assignm=
 ent.  Using the SAME spelling for "is-equal-to" and "assignment" is unfortu=
 nate, and is something that many languages avoid.  Many languages that use =
 "=3D" for assignment use a SEPARATE "=3D=3D" operator for comparison; this =
 includes C, C++, Java, C#, Python, and Perl.  Many languages (like Pascal) =
 that use "=3D" for comparison use another spelling like ":=3D" for assignme=
 nt, again, to keep their spellings separate (these languages can often disa=
 mbiguate from context... but they intentionally don't).  It is odd that the=
  shell, unlike all these languages, conflates their spellings.  It's too la=
 te to get rid of "=3D" for comparison, but it's easy to add "=3D=3D" as a s=
 ynonym, which is what is proposed.  So adding this ability (1) clarifies wh=
 ether assignment or comparison is being used, and (2) improves consistency =
 between shell and other languages that use "=3D" 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 bas=
 h, 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. A=
 t least.  *ALL* of these implementations agree that "=3D=3D" is a synonym f=
 or "=3D", so there's no question about "different semantics so which one sh=
 ould we implement?".
 
 This extension is already in wide use in shell scripts, even ones not writt=
 en for bash.  Several NetBSD bugs have been filed because NetBSD can't hand=
 le "=3D=3D".  Can you change the scripts?  Sure.  But why not add the facil=
 ity 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 b=
 ash, such as OpenBSD's /bin/sh or Busybox /bin/sh, can use "=3D=3D", and th=
 ese shells don't support many extensions.  Busybox focuses on being as tiny=
  as possible, and even they found it useful to support "=3D=3D".
 
 --- David A. Wheeler
 


Home | Main Index | Thread Index | Old Index