FreeKB - Add values to an array in Bash (+=)
Add values to an array in Bash (+=)

Home > Search

Let's say you have an array of fruit.

fruit=(banana apple orange grapes)


The += operator can be used to append values to the array. In this example, pineapple is appended to the fruit array.



The array can be printed.

echo $fruit


Echoing the array will show that pineapple has been appended to the array.

banana apple orange grapes pineapple


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 99ced in the box below so that we can be sure you are a human.