Set
array_diff¶
Print elements present in arr_a but not in arr_b.
Example¶
arr1=( a b c d )
arr2=( b d e )
array_diff arr1 arr2
# => a
# => c
Arguments¶
- $1 (string): Name of the first array variable.
- $2 (string): Name of the second array variable.
Exit codes¶
- 0: Always
Output on stdout¶
- Elements from arr_a not in arr_b, one per line.
array_intersect¶
Print elements present in both arr_a and arr_b.
Example¶
arr1=( a b c d )
arr2=( b d e )
array_intersect arr1 arr2
# => b
# => d
Arguments¶
- $1 (string): Name of the first array variable.
- $2 (string): Name of the second array variable.
Exit codes¶
- 0: Always
Output on stdout¶
- Elements common to both arrays, one per line.
array_union¶
Print all unique elements from both arrays (set union).
Example¶
arr1=( a b c )
arr2=( b c d e )
array_union arr1 arr2
# => a
# => b
# => c
# => d
# => e
Arguments¶
- $1 (string): Name of the first array variable.
- $2 (string): Name of the second array variable.
Exit codes¶
- 0: Always
Output on stdout¶
- All unique elements from both arrays, one per line.
array_unique¶
Remove duplicate elements from a named array in place, preserving order.
Example¶
myarr=( a b a c b d )
array_unique myarr
printf '%s\n' "${myarr[@]}"
# => a
# => b
# => c
# => d
Arguments¶
- $1 (string): Name of the array variable.
Exit codes¶
- 0: Always