Given a pipe of the form C1 | C2
, if C2
takes more than one positional argument, is it possible to choose where the output of C1
is going?
Consider the following example.
$ cat myscript
#!/bin/bash
cat $1
cat $2
$ cat world.txt
World
$ echo "Hello" | ./myscript world.txt
World
Hello
I want the final output to be in correct order (Hello World) by altering only the right side of the pipeline.
C1
output is not going into$2
. Addecho <$2>
to the script and you will see that. So the whole premise of your question is not correct.stdout
of one program to thestdin
of the other. It has nothing to do with the script arguments. What you see happening is that$2
is actually empty in your example so the lastcat
reads fromstdin
which then comes from the pipe.cat
.cat
(concatenate) will read all files mentioned in its argument lists and output them one after another. Same as what your script is trying to do, but for more and less than 2.