shorthand for feeding contents of multiple files to the stdin of a script
You can use cat
and a pipe:
cat file1 file2 file3 ... fileN | ./script
Your example, using a pipe, and no temp file:
join file1.txt file2.txt | ./script
If you don't want to use a pipe, you can use input redirection with process substitution:
./script <(cat file1 file2)
To add on @Jonah Braun's answer, if you ever need to add process output into your script as well, i.e. your file might not be on your disk but accessed via URL
using curl
or a similar tool.
Something like this could be used to get stdout
of multiple processes and use them in a script via stdin
This will be the script to handle input
Contents of multi-input.sh
:
#!/usr/bin/env bash
while read line; do
echo $line
done
Now test it:
$ ./multi-input.sh < <(cat <(echo process 1) <(echo process 2) <(echo process 3))
Output:
process 1
process 2
process 3
<()
turns process into a virtual file
using fd
if you will, so <
is needed to read it. cat
itself doesn't need it because it does what it does, concatenates files, virtual or real.