bug-bash
[Top][All Lists]
Advanced

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

Re: setvalue builtin command


From: konsolebox
Subject: Re: setvalue builtin command
Date: Wed, 3 Apr 2013 23:53:48 +0800

Hi. I made a post on this before but I haven't got a reply. I actually want
to know what people think about the idea as I actually find a command like
this really helpful. Anyone please?

On Wed, Feb 6, 2013 at 11:30 AM, konsolebox <address@hidden> wrote:

> Hi. I was wondering if we could add a builtin where we could use it as an
> alternative for assigning values to a parameter. And thought of a builtin
> name called setvalue. With it we could assign values to a normal variable,
> an array, or an associative array.
>
> For normal variables we could have the simple syntax:
>
> setvalue VARIABLE "something"
>
> For array variables:
>
> setvalue -a VARIABLE A B C D
>
> Or alternatively:
>
> setvalue -a VARIABLE "[1]=ABCD 1234" "[4]=WXYZ 7890"
>
> For associative array variables, we have need to have them in pairs:
>
> setvalue -A VARIABLE "Key1" "Value1" "Key2" "Value2"
>
> With this we could prevent using eval in situations like when we had to
> assign values to passed custom variable names inside a function. We could
> use declare or typeset but those builtin functions tend to create variables
> as local by default and using the -g option would be confusing if the
> intended use of the variable is local.
>

About accepting indices in indexed arrays by the way I also had the idea of
adding the option -i to make it more consistent:

setvalue -a -i VARIABLE "[1]=ABCD 1234" "[4]=WXYZ 7890"

So setvalue would only only entertain indices if the option is added and
just treat them as a normal part of the value if not.

setvalue could also have alternative names like setval / setv / or set -V
perhaps.


reply via email to

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