Suppose a bash script expects an argument to be a file. But we have a bash array, and would like to provide the array in some way as an argument to the script, as if there were a file whose lines are the elements of the array. I wonder how to do that?
For a simple example, I have a script myscrpt containing a single command, which expects a file argument
cat $1
and I have an array
arr=( 1 3 5 )
and how can I provide arr as an argument to the script, as if the argument is actually a file whose content is
1
3
5
does myscript <(echo "${arr[@]}") work?
Thanks.
commmay solve my ultimate problem (but needssorton the file arguments, which change the line order, undesirably). But right now I just wonder if a script is expecting a file argument, how can I provide an array to it?