[Top][All Lists]

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

Re: variable name and its' value are the same characters causes recursio

From: Maarten Billemont
Subject: Re: variable name and its' value are the same characters causes recursion error
Date: Fri, 11 Mar 2011 08:20:46 +0100

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 

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]