Shift
array_shift¶
Remove the first n elements from a named array in place. From https://www.reddit.com/r/bash/comments/aj0xm0/quicktip_shifting_arrays/
Arguments¶
- $1 (string): Name of the array variable.
- $2 (int): Number of elements to shift off (default: 1).
Exit codes¶
- 0: Always
array_rotate¶
Rotate elements of a named array left by n positions. Negative n rotates right.
Example¶
myarr=( a b c d e )
array_rotate myarr 2
printf '%s\n' "${myarr[@]}"
# => c
# => d
# => e
# => a
# => b
Arguments¶
- $1 (string): Name of the array variable.
- $2 (int): Number of positions to rotate left (default: 1). Negative rotates right.
Exit codes¶
- 0: Always