Redirect stdin in a script to another process
bash, pipe
Solution
When you write a bash script, the standard input is automatically inherited by any command within it that tries to read it, so, for example, if you have a script `myscript.sh` containing:
#!/bin/bash
echo "this is my cat"
cat
echo "I'm done catting"
And you type:
$ myscript.sh < myfile
You obtain:
this is my cat
<... contents of my file...>
I'm done catting
Problem
Say I have a bash script that get some input via stdin. Now in that script I want to launch another process and have that process get the same data via its stdin. ``` #!/bin/bash echo STDIN | somecommand ``` Now the "echo STDIN" thing above is obviously bogus, the question is how to do that? I could use read to read each line from stdin, append it into a temp file, then ``` cat my_temp_file | somecommand ``` but that is somehow kludgy.