In unix, the standard file descriptors stdin, stdout, and stderr are numbered
0, 1, and 2, respectively. I've always done descriptor redirection, such as:
grep ^Poop myfile.txt 2>&1 > /dev/null
This will redirect
stderr (fd #2) to stdout (fd #1). stdout is then redirected to /dev/null.
What I never bothered trying was redirecting
The output is just how I want:stdin
#!/bin/sh
echo "Printing output:"
sed -e 's/^./Output: &/' <&0
Note the <&0 - this will use our stdin as the stin for sed.
Now, let's try running it:
ls | ./myscript
whack(~/bin) [590] > /bin/ls | sh myls.sh
Printing output:
Output: Mrandom
Output: fix
Output: hostlist
Output: intarweb
Output: logtail
Output: malbums
Output: mclear
Output: minfo
Output: myls.sh