Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #11387
| Path | csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Dan Douglas <ormaaj@gmail.com> |
| Newsgroups | gnu.bash.bug |
| Subject | Working with array keys (was Re: Parameter Expansion: Case Modification: ${var~} not documented) |
| Date | Tue, 18 Aug 2015 17:31:41 -0500 |
| Lines | 47 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.8586.1439937108.904.bug-bash@gnu.org> (permalink) |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | usenet.stanford.edu 1439937108 28471 208.118.235.17 (18 Aug 2015 22:31:48 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| Cc | Isaac Good <isaacgood@gmail.com>, "bug-bash@gnu.org" <bug-bash@gnu.org> |
| To | Chester Ramey <chet.ramey@case.edu> |
| Envelope-to | bug-bash@gnu.org |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=AAKGQ3pZyJSQMppO7lPn//tZAiBjjptAInGfvRWDiOw=; b=fKHww7XVHLhf+ZhNV0XEeDWtgfFn5stcvWeLYhYm7ObwYTwCn2EirB8HixGxfYSwdJ FN5x7VfHMix8lcjO81O++TrZ2qXc4xHLgb/NEk8Pd2lrItZRe3rmqcFpFwEtZpLxIOb6 UVhaxmgXUE0SzDY1aLX9bw9bxNjBQnO+IBMlx1rA2YxN9JVIDbpO12f0skqUzIxT5RdW u2UUDm9VuoWRn4rNhtZtgWFxvzTic3PvGIuvBwLKay2mZ4iS19LCOailVqpoRXZoNhIJ IgEZG0+3wnq5qYCns97ExVrkmcBm/WGfFfaJb81aR1EKmLM2he6bp6y2ZRsn1D3rFRH+ W0GQ== |
| X-Received | by 10.107.136.148 with SMTP id s20mr8912722ioi.135.1439937101589; Tue, 18 Aug 2015 15:31:41 -0700 (PDT) |
| X-detected-operating-system | by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). |
| X-Received-From | 2607:f8b0:4001:c06::22f |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.14 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <http://lists.gnu.org/archive/html/bug-bash> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| Xref | csiph.com gnu.bash.bug:11387 |
Show key headers only | View raw
On Tue, Aug 18, 2015 at 3:50 PM, Chet Ramey <chet.ramey@case.edu> wrote:
> On 8/18/15 1:43 PM, Dan Douglas wrote:
>> On Tuesday, August 18, 2015 9:54:55 AM CDT Isaac Good wrote:
>>> Would you mind sharing the rational behind having it undocumented?
>>
>> Since I like guessing: the syntax for parameter expansion operators is
>> currently non-extensible, so the namespace of terse operators is in limited
>> supply. New syntax should be extensible to suit future needs while keeping the
>> language minimal. This is new syntax that adds one function that will be
>> rarely used. I can think of better ways to use that operator.
>
> This is true, and I would prefer to not set the ~ `operator' in stone until
> I'm more satisfied with how it works.
>
> Bash-4.4 has the ${param@operator} family of expansions (inspired by a
> similar feature in mksh) as the extensible syntax you're asking for.
>
Ah yeah. I saw the var@Q already. That will be nice!
> I assume you mean the difference betweeen ${!param[@]/followed/bysomething}
> and ${!param[@]}.
Yeah that sort of thing. E.g. a recent example where my best answer is still
pretty bad even with fancy bash 4.3-isms. It would be quite nice to get rid of
the intermediary `keys` array just to look up the keys of keys.
~ $ bash <<\EOF
function rev {
typeset -n _ref=$1 _ret=$2
typeset -a keys=("${!_ref[@]}")
typeset key=0
for ((; key <= ${#keys[@]}; key++)); do
_ret[${keys[key - 1]}]=${_ref[${keys[-key]}]}
done
}
typeset -a a=([0]=a [1]=b [3]=c) b
rev a b
typeset -p b
EOF
declare -a b='([0]="c" [1]="b" [3]="a")'
Thats maybe a little tricky. What doesn't work now is ${!_ref[@]:(-(key)):1}
Back to gnu.bash.bug | Previous | Next | Find similar
Working with array keys (was Re: Parameter Expansion: Case Modification: ${var~} not documented) Dan Douglas <ormaaj@gmail.com> - 2015-08-18 17:31 -0500
csiph-web