help-bash
[Top][All Lists]
Advanced

[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: Quentin L'Hours
Subject: Re: [Help-bash] Fastest way to join an array into a string
Date: Mon, 26 Aug 2019 11:55:01 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1

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



reply via email to

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