Problem:
cat
works reads multiple files within a brace {}
;
cat {file1,file2}.txt
But not when the braced part is specified by a variable.
VAR="{file1,file2}"
cat $VAR.txt
I suspect, as referenced here, this is because quotes are read literally in a variable. So cat
is trying to find {file1,file2}.txt
which doesn't exist.
Is there a way to specify multiple files as a single element in a variable?
Context:
For my full script I want to loop cat
through a set of braced and unbraced file prefixes. So simply setting VAR=( file1 file2)
won't help me.
VAR=( "{file1,file2}" file3 file4 )
for i in ${VAR[@]}; do cat $i.txt > merged$i.txt; done