Assuming you've started with something like this
folder1=10 folder2=4 folder3=7 You can write it out with a command such as this
set | grep -E '^folder[0-9]+=' > counter.txt To read it back in again you can simply source the file
source counter.txt If you have a shell that handles arrays (bash, zsh) you can index the set of folders to an arbitrarily large number
folder[1]=10 folder[2]=4 folder[3]=7 And write this one variable array out with
set | grep '^folder=' > counter.txt Read it back in using source, as above.
For arrays you would reference them like this echo "${folder[1]}" or foreach f "${folder[@]}"; do ... done. Or even this if your index values are in strict ascending order from 1:
i=1 while [[ $i -le ${#folder[*]} ]] do echo "$i => ${folder[$i]}" ((i++)) done