Skip to main content
In this lesson, you’ll learn two key operations for managing Bash arrays:
  1. Removing a specific element by its index
  2. Clearing all elements in one command
The image is a slide titled "Arrays remove," showing two checked items: "How to remove a specific element from an array" and "How to remove all of the elements from an array in one shot."

Removing a Specific Element by Index

To delete a single entry in a Bash array, use unset with the array name and the target index:
Running this script produces:
Bash does not reindex arrays after removal. The original indices remain, leaving gaps in the sequence.
To view both values and their indices after deletion:

Clearing All Elements

If you need to empty an array completely, omit the brackets when using unset:
No output appears because the array has been removed.
Using unset array deletes the entire variable. You must redeclare it before adding new elements.

Summary of Removal Operations

Watch Video