Using the research you already did and that I commented to (by not knowing it was an answer to your own question), here is the full delayed_netcat.sh
:
#!/bin/bash
read line
netcat "${@}" < <(echo $line ; cat)
This first waits for a line of input and later prepends that line using a simple echo
to the "newly generated" input to the actual netcat
. The rest of stdin is just redirected using cat
which slurps it from stdin
and adds it to the input of netcat
. It also supports passing commandline options and arguments to the "real" netcat
.
The usage is as follows:
netcat -l 12345 | cmd1 | cmd2 | ... | ./delayed_netcat.sh localhost 54321
The netcat
is delayed till the first line is read. If you really want to start it after the first character is read the parts with read
and echo
need some rewrite.