I would like to delegate netcat stdin and stdout to a function.
I can do the following to redirect stdout only
nc -l -p 1234 | my_function
I can do the following to redirect stdin only
nc -l -p 1234 < <(my_function)
I would like to delegate netcat stdin and stdout to a function.
I can do the following to redirect stdout only
nc -l -p 1234 | my_function
I can do the following to redirect stdin only
nc -l -p 1234 < <(my_function)
When my_function is wrapped as an executable form (file), you can use -e
option of netcat:
nc -l -p 1234 -e my_function
However if it's a function in bash, starting Bash 4.0 you can use coproc
:
coproc my_function
nc -l -p 1234 <&"${COPROC[0]}" >&"${COPROC[1]}"