The following works as you would like in bash
and zsh
:
$ array=(pluto pippo)
$ delete=pluto
$ echo ${array[@]/$delete}
pippo
$ array=( "${array[@]/$delete}" ) #Quotes when working with strings
If need to delete more than one element:
...
$ delete=(pluto pippo)
for del in ${delete[@]}
do
array=("${array[@]/$del}") #Quotes when working with strings
done
from: https://stackoverflow.com/questions/16860877/remove-an-element-from-a-bash-array
No comments:
Post a Comment