bash: Redirect all STDIN to a file

Hi,

to simply redirect all incoming input from STDIN to a file you can use less.

Create a shell script /tmp/stdinredirect.sh

#!/bin/bash
less  <&0 >> /tmp/stdindata.txt

This scripts appends all data from STDIN to the file /tmp/stdindata.txt
Set execute permissions and check

michael@debedv ~ # chmod u+x /tmp/stdinredirect.sh
michael@debedv ~ # echo Test STDIN | /tmp/stdinredirect.sh
michael@debedv ~ # cat /tmp/stdindata.txt
Test STDIN 

Michael

Leave a Reply