Dynamically Appending Elements to a Bash Array

Following is how to dynamically append (push) items to an array in a bash script.

declare -a ARRAY=()

ARRAY=("${ARRAY[@]}" "item1")

ARRAY=("${ARRAY[@]}" "item2")

Leave a Reply