Skip to main content
Updated to work with values that contain spaces, thanks @hackerb9
Source Link
Steve Kehlet
  • 6.5k
  • 5
  • 44
  • 43

You could build up a new array without the undesired element, then assign it back to the old array. This works in bash:

array=(pluto pippo) new_array=() for value in "${array[@]}" do [[ $value != pluto ]] && new_array+=($value"$value") done array=("${new_array[@]}") unset new_array 

This yields:

echo "${array[@]}" pippo 

You could build up a new array without the undesired element, then assign it back to the old array. This works in bash:

array=(pluto pippo) new_array=() for value in "${array[@]}" do [[ $value != pluto ]] && new_array+=($value) done array=("${new_array[@]}") unset new_array 

This yields:

echo "${array[@]}" pippo 

You could build up a new array without the undesired element, then assign it back to the old array. This works in bash:

array=(pluto pippo) new_array=() for value in "${array[@]}" do [[ $value != pluto ]] && new_array+=("$value") done array=("${new_array[@]}") unset new_array 

This yields:

echo "${array[@]}" pippo 
Source Link
Steve Kehlet
  • 6.5k
  • 5
  • 44
  • 43

You could build up a new array without the undesired element, then assign it back to the old array. This works in bash:

array=(pluto pippo) new_array=() for value in "${array[@]}" do [[ $value != pluto ]] && new_array+=($value) done array=("${new_array[@]}") unset new_array 

This yields:

echo "${array[@]}" pippo