Concat

array_copy

Copy a named array to another named array.

Example

myarr=( a b c )
array_copy myarr copy
printf '%s\n' "${copy[@]}"
# => a
# => b
# => c

Arguments

  • $1 (string): Name of the source array variable.
  • $2 (string): Name of the destination array variable.

Exit codes

  • 0: Always

array_concat

Concatenate one or more named arrays into a destination named array.

Example

arr1=( a b c )
arr2=( d e f )
array_concat arr1 arr2
printf '%s\n' "${arr1[@]}"
# => a
# => b
# => c
# => d
# => e
# => f

Arguments

  • $1 (string): Name of the destination array variable.
  • ... (string): Names of one or more source array variables to concatenate in.

Exit codes

  • 0: Always

array_append

Append one or more elements to a named array.

Example

myarr=( a b c )
array_append myarr d e
printf '%s\n' "${myarr[@]}"
# => a b c d e

Arguments

  • $1 (string): Name of the array variable.
  • ... (string): One or more elements to append.

Exit codes

  • 0: Always

array_prepend

Prepend one or more elements to the front of a named array.

Example

myarr=( c d e )
array_prepend myarr a b
printf '%s\n' "${myarr[@]}"
# => a b c d e

Arguments

  • $1 (string): Name of the array variable.
  • ... (string): One or more elements to prepend.

Exit codes

  • 0: Always

array_zip

Interleave elements from two arrays, pairing by index. Stops at the shorter array's length.

Example

keys=( a b c )
vals=( 1 2 3 )
array_zip keys vals
# => a 1
# => b 2
# => c 3

Arguments

  • $1 (string): Name of the first array variable.
  • $2 (string): Name of the second array variable.

Exit codes

  • 0: Always

Output on stdout

  • Paired elements as space-separated lines.