Skip to content

Instantly share code, notes, and snippets.

@andrwj
Forked from Integralist/bash-array-shift.sh
Created February 2, 2019 09:47
Show Gist options
  • Save andrwj/3d6e9918e97105f2dec19b780929091f to your computer and use it in GitHub Desktop.
Save andrwj/3d6e9918e97105f2dec19b780929091f to your computer and use it in GitHub Desktop.
Zsh and Bash Array Shift (remove first item from the Array)
array=(foo, bar, baz)
echo ${array[@]} # => foo, bar, baz
array=("${array[@]:1}")
echo ${array[@]} # => bar, baz
array=("${array[@]:1}")
echo ${array[@]} # => baz
array=(foo, bar, baz)
echo $array # => foo, bar, baz
array=("${(@)array:1}")
echo $array # => bar, baz
array=("${(@)array:1}")
echo $array # => baz
# UPDATE: this works as well and is less confusing syntax
array=(${array:1})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment