Last active
March 7, 2022 05:27
-
-
Save Integralist/eb7bf0d8f3b7d9958f13 to your computer and use it in GitHub Desktop.
Zsh and Bash Array Shift (remove first item from the Array)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
array=(foo, bar, baz) | |
echo ${array[@]} # => foo, bar, baz | |
array=("${array[@]:1}") | |
echo ${array[@]} # => bar, baz | |
array=("${array[@]:1}") | |
echo ${array[@]} # => baz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
For zsh (might work in bash too) (might require some options)
or destructively