Skip to content

Instantly share code, notes, and snippets.

@bhenderson
Last active December 18, 2015 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhenderson/5851951 to your computer and use it in GitHub Desktop.
Save bhenderson/5851951 to your computer and use it in GitHub Desktop.
NetCat (nc) pipe. Using coproc available in bash 4.
#!/bin/bash
server=$1
port=$2
lport=${3:=$port}
# stdout will be server
# stderr will be client
exec 3>&1
# use coproc instead of named pipe.
# bash 4
coproc { nc $server $port | tee >( cat >&3 ) ;}
{ nc -lk -p $lport | tee >( cat >&2 ) ;} <&${COPROC[0]} >&${COPROC[1]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment