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

Advertisment to support michlstechblog.info

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.