On Thu, Apr 4, 2013 at 8:51 PM, konsolebox <konsole...@gmail.com> wrote:

> Another "feature" of this kind of construct is that you can put the name
>> of the variable-to-be-assigned into another variable:
>>
>> ptr=some_variable
>> setvalue "$ptr" "$foo"
>>
>> Which may be a good thing or a bad thing, but either way it's definitely
>> a thing that someone will (ab)use if it's available.
>>
>
> Well I did considered that noting that many people already tend to use the
> eval hack just to assign values to variables carried inside another
> variable most likely through passing of functions..
>
>
>> That said, I don't think bash needs this.  Bash 4.3 is going to have
>> "namerefs" (declare -n) to allow passing arguments by reference to a
>> function.
>>
>
> I should have seen this sooner (have bash-devel but didn't check new
> features). I think it would be enough for the need.
>
> Thanks for telling me. Can't wait to use the feature soon. That would
> simplify many parts of my codes.
>

On second thought I think we still need the function since for declare -n:

a) Reference variable could not be an array.

b) Same risk is at hand if a variable name passed to the function is not
valid thereby making the error "invalid variable name for name reference".
So anyone could still abuse it.

So adding a function like setvalue would still be a good thing for a
general purpose.

Reply via email to