Ambiguous redirect when redirecting to multiple files using Bash
That's what tee is for:
command | tee file1 file2 file3 > file4
tee also outputs to stdout, so you may want either to put one file after a redirect (as shown above), or send stdout to /dev/null
.
For your case:
echo "" | tee /home/jem/rep_0[1-3]/logs/SystemOut.log >/dev/null
I had this same question and just wanted to add the example with the wildcard since it hadn't been shown. I think this is what you were looking for:
echo "" | tee *.log
You can do this using tee
, which reads from stdin and writes to stdout and files. Since tee
also outputs to stdout, I've chosen to direct it's output to /dev/null
. Note that bash expansion matches against the existing files, so the files you're trying to write to must exist before executing this command for it to work.
$ echo "" | tee /home/jem/rep_0[1-3]/logs/SystemOut.log > /dev/null
As a side note, the ""
you pass to echo
is redundant.
Not directly relevant to your question, but if you don't rely on bash expansion you can have multiple pipes.
$ echo hello > foo > bar > baz
$ cat foo bar baz
hello
hello
hello
You can do this:
echo "" | tee /home/jem/rep_0{1..3}/logs/SystemOut.log
To suppress the output to stdout, add this to the end of the commands above:
> /dev/null
The echo
command in your question (which doesn't require the empty quotes) simply puts a newline in the files. If you want to create empty files, use the touch
command.