1

I have 5 files called file1, file2, file3, file4, file5, . I am attempting to run the following command echo "contents" >> file{1,2,3,4,5}. I get the following error when I run this command; -bash: file{1,2,3,4,5}: ambiguous redirect. My goal is to echo some text to multiply files in one command. How can I achieve this? Thanks in advance.

1 Answers1

4

You can't redirect to multiple files. Instead, use tee -a (-a for "append", since in your question you use the appending redirect operator >>):

echo "contents" | tee -a file{1,2,3,4,5}

Another option is to use zsh instead of bash, which can redirect to multiple files:

[birdsnest ~]% echo foo > /tmp/{foo,bar}
[birdsnest ~]% cat /tmp/foo 
foo
[birdsnest ~]% cat /tmp/bar 
foo
jayhendren
  • 8,384
  • 2
  • 33
  • 58