I would like to have a logging function that takes filenames as arguments and replicate the stdout to all of these files. This is what I have come up so far:
function logger() {
exec > >(tee -ia /var/log/{log1,log2})
}
When I try to replace {log1,log2}
with {$*}
, I get the arguments separated by space. So, I thought I would do something like this:
function logger() {
exec > >(IFS=,; tee -ia /var/log{"$*"}
}
This fails to do what I want as brace expansion happens before moving on to the variable substitution. So, I thought I could do this:
function logger() {
exec > >(IFS=,; eval "tee -ia /var/log/\{$*\}")
}
But this behaves the same, ie logger one two
creates one single file named {one,two}
.
Why is that? How can I get brace expansion to work so that tee
writes to multiple files?