On 10 Mar 2011, at 15:23, Chet Ramey wrote: > > On 3/10/11 8:14 AM, Greg Wooledge wrote: >> On Thu, Mar 10, 2011 at 10:18:26AM +0800, Clark J. Wang wrote: >>> Actually I don't like the recursion here. Does POSIX require that? >>> >>>> For example: >>>> >>>> unset a; declare a="a"; [[ a -lt 3 ]]; echo $? >>>> bash: [[: a: expression recursion level exceeded (error token is "a") >>>> 1 >> >> POSIX doesn't even have a [[ command. This is all bash. > > Not really. There is substantial agreement among shells that implement > arithmetic expansion. bash, ksh93, zsh, mksh (and other pdksh derivatives > that implement `[[') all behave the same way. For the most part, it's the > same way with `['; zsh is a notable exception there. > > Chet
Personally, I would much rather see (( a )) fail if a doesn't contain a number rather than go search for a parameter named by its contents. If the parameter a contains a word that's not a number, I can't imagine any case where this would be an expected and wanted scenario, rather than a bug. If it were expected, the author would've used the indirection operator directly. Which leaves us with a bug, one that's often terribly hard to detect and diagnose. That's ignoring the fact that you're leaving the door wide open for user input to go and load any parameter it chooses in its stead. Really, whenever this happens, it's either breaking things in completely unexpected and often invisible ways or it's somebody exploiting your code to do something it wasn't supposed to or reveal something it doesn't want to show. Why would we want this "feature"?