unix shell, redirect output but keep on stdin

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-05-17T17:43:39Z Indexed on 2010/05/17 17:51 UTC
Read the original article Hit count: 213

Filed under:
|
|

I'd like to have a shell script redirect stdout of a child process in the following manner

  1. Redirect stdout to a file
  2. Display the output of the process in real time

I know I could do something like

#!/bin/sh

./child > file
cat file

But that would not display stdout in real time. For instance, if the child was

#!/bin/sh

echo 1
sleep 1
echo 2

The user would see "1" and "2" printed at the same time

© Stack Overflow or respective owner

Related posts about unix

Related posts about shell