Write bash array to file with newlines
arrays, bash
Solution
Use `printf` instead:
printf "%s\n" "${testa[@]}" > file.txt
cat file.txt
1
2
3
Problem
How do I write an array to a file such that each element is separated by a newline? The following does not work: ``` testa=( 1 2 3 ) echo "${testa[@]}" > file.txt ``` (now the elements are separated by spaces on a single line) I would like avoid writing a `for` loop for this...