Join an array contents with a string separator.
join-array
converts an array to string by joining its values with given
string.
Join an array contents by a string. It is similar to PHP implode
function.
The separator allows for escaped special characters (e.g. \n
and \t
)
by being pre-processed with printf '%b'
source "${BASH_SOURCE[0]%/*}/libs/biapy-bashlings/src/join-array.bash"
declare -a 'example_array'
example_array=('Dancing' 'on the tune of' 1 'array contents' )
example_string="$(
join-array ' ~8~ ' ${example_array[@]+"${example_array[@]}"}
)"
- $1 (string): The separator used to join the array contents.
- ... (mixed): The contents of the joined array.
- 0: If the array contents is join successfully.
- 1: If an argument is missing.
- The
$@
array contents joined by$1
separator.
- Error if an argument is missing.