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: Thu, 4 Apr 2013 20:32:21 +0800

On Thu, Apr 4, 2013 at 3:26 PM, Dan Douglas <address@hidden> wrote:

> On Wednesday, April 03, 2013 11:53:48 PM konsolebox wrote:
> > 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.
>
> This is more or less identical to the ksh88 `set -A'. If anything were to
> be
> added, it would probably be that. I assume Chet preferred enforcing more
> consistent syntax rather than adding something redundant to ksh93-like
> compound assignment syntax.
>

I actually had the idea based from ksh93 but unfortunately set -A only
assigns multiple values for indexed arrays starting at subscript 0 and
won't allow specific positions like how we could do it in VAR=(...) e.g.
VAR=([1]="A" "B" [2]="C") (noting for later that B gets overrided with C).
Moreover it won't assign values for normal variables like 'setvalue VAR
value'; and add values for associative arrays like 'setvalue -A VAR "key1"
"value1" "key2" "value2"'.


>
> The primary advantages to set -A are:
>
>  - It's the most portable way to assign multiple elements to an indexed
> array
> other than a separate assignment for each element.
>

Yes but it would only give us limit to that feature.


>  - The combination `set -sA' provides a means of sorting
> (lexicographically).
> Bash currently has no built-in way to sort an array or the positional
> parameters.
>

Well if we are to use another more capable function then we don't really
have to follow the rule. And I believe that that could be included as well
(setvalue -as), but we don't really have to add the sorting feature for now
if it would be difficult or heavy to implement.

Also to add, having -a for indexed arrays and -A for associative arrays
would be less confusing since local, typeset, and declare statements use
them likewise.

Just came up. We could also add another option to make setvalue -a [-i] act
like VAR+=(...).

Ross


reply via email to

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