Remove
array_clear¶
Empty a named array in place.
Arguments¶
- $1 (string): Name of the array variable.
Exit codes¶
- 0: Always
array_remove¶
Remove all elements matching a value from a named array and reindex.
Example¶
myarr=( a b c b d )
array_remove myarr b
printf '%s\n' "${myarr[@]}"
# => a
# => c
# => d
Arguments¶
- $1 (string): Name of the array variable.
- $2 (string): The value to remove.
Exit codes¶
- 0: Always
array_remove_first¶
Remove only the first element matching a value from a named array and reindex.
Example¶
myarr=( a b c b d )
array_remove_first myarr b
printf '%s\n' "${myarr[@]}"
# => a
# => c
# => b
# => d
Arguments¶
- $1 (string): Name of the array variable.
- $2 (string): The value whose first occurrence to remove.
Exit codes¶
- 0: Always
array_pop¶
Remove and print the last element of a named array.
Example¶
myarr=( a b c )
array_pop myarr
# => c
printf '%s\n' "${myarr[@]}"
# => a
# => b
Arguments¶
- $1 (string): Name of the array variable.
Exit codes¶
- 0: Always
Output on stdout¶
- The removed last element.
array_insert¶
Insert one or more elements into a named array at a given index. Existing elements at and after the index are shifted right.
Example¶
myarr=( a b d e )
array_insert myarr 2 c
printf '%s\n' "${myarr[@]}"
# => a
# => b
# => c
# => d
# => e
Arguments¶
- $1 (string): Name of the array variable.
- $2 (int): Zero-based index at which to insert.
- ... (string): One or more elements to insert.
Exit codes¶
- 0: Always
array_splice¶
Remove elements from a named array at a given position, optionally inserting replacements. Prints the removed elements, one per line.
Example¶
myarr=( a b c d e )
array_splice myarr 1 2
# => b
# => c
printf '%s\n' "${myarr[@]}"
# => a
# => d
# => e
Arguments¶
- $1 (string): Name of the array variable.
- $2 (int): Start index (supports negative indices from end).
- $3 (int): Number of elements to delete (default: all remaining from start index).
- ... (string): Optional replacement elements to insert at the start position.
Exit codes¶
- 0: Always
Output on stdout¶
- The removed elements, one per line.