#!/bin/bash unset a declare -a a c=0 function t() { c+=1 a+=(bly $c) } for i in {1..10}; do t done for i in "${a[@]}"; do echo $i done