[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Fastest way to join an array into a string
From: |
Peng Yu |
Subject: |
Re: [Help-bash] Fastest way to join an array into a string |
Date: |
Mon, 26 Aug 2019 13:58:34 -0500 |
It doesn't work if the separator is a string of more than one characters.
On Mon, Aug 26, 2019 at 1:55 PM Quentin L'Hours <address@hidden> wrote:
>
> Hi,
>
> On 2019-08-26 11:47 a.m., Peng Yu wrote:
> > I'd like to do something similar to str.join() in python.
> >
> > Suppose the array is in $@, I currently use the following code to
> > print the joined result ($separator contains the separator to join the
> > string). Is it the fastest way to do so in bash? Thanks.
>
> You could use "$*" which is a single string of all the args separated by
> the first letter of the IFS:
>
> $ set a b c
> $ IFS=/
> $ printf '%s\n' "$*"
> a/b/c
--
Regards,
Peng