help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] What is the most efficient way to extract the first elem


From: Pierre Gaston
Subject: Re: [Help-bash] What is the most efficient way to extract the first element of "address@hidden"?
Date: Thu, 22 Feb 2018 09:09:53 +0200

On Thu, Feb 22, 2018 at 6:57 AM, Peng Yu <address@hidden> wrote:

> Hi,
>
> I have to assign "address@hidden" to an array and then extract the first
> element. If I understand it correctly, this will involve an extra copy
> which may be slow for large arrays. Is there a syntax that allows the
> direct extraction of the first element of "address@hidden"? Thanks.
>
> $ x=()
> $ x[10]=a
> $ x[2]=b
> $ i=("address@hidden")
> $ echo "${i[0]}"
> 2
>
> --
> Regards,
> Peng
>
>
I don't think there is something much better than this, you can probably
avoid some extra assignments eg:

x=([2]=b [10]=a)
for first in "address@hidden";do break;done;echo "$first"

But it will still be pretty slow on large array, maybe you could keep track
of it manually?


reply via email to

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