1

Testing with the linux command line and pipe I tried to do echo {1..3} | touch and it doesn't work. I achieved the results with touch $(echo {1..3}).

Why I can't pass the list generated by echo to touch using the pipe as in the first example?

1 Answers1

6

Thanks to steeldriver for his comment, it guided me to the answer.

The pipe operator only works when the command accepts arguments from stdin, in this case commands like touch or rm does not, an alternative solution is to use command sustitution as in the example

touch $(echo {1..3})

Or by using the xargs which converts input from standard input into arguments to a command, hence is possible to do

echo {1..3} | xargs touch

as simple as that