Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash: copy stdin to file

Tags:

bash

stdin

I have two programs. First one is client and the second one is server. they exchange data in text format using stdin and stdout.

I would like to put proxy bash script between them and record everything coming from stdin to a file.

I tried the following code, but /tmp/f-copy.txt is empty

Proxy.sh:

exec 6<&0
exec 6>/tmp/f-copy.txt
server

What do I do wrong?

like image 494
Antonio Avatar asked Jan 20 '26 11:01

Antonio


1 Answers

Look at the tee command, it's what you want. From the man page:

The tee utility copies standard input to standard output, making a copy in zero or more files. The output is unbuffered.

like image 142
Diego Basch Avatar answered Jan 23 '26 20:01

Diego Basch