Skip to content

Instantly share code, notes, and snippets.

@mendess
Last active April 15, 2020 18:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mendess/54098e31c40f6b83d5984a0634bfd3a1 to your computer and use it in GitHub Desktop.
Save mendess/54098e31c40f6b83d5984a0634bfd3a1 to your computer and use it in GitHub Desktop.
A simple chat written in bash
#!/bin/bash
if [[ "$1" = *-h* ]]
then
cat <<EOF
Usage:
Server: $0
Client: $0 SERVER_IP
EOF
exit
fi
if [ -z "$1" ]
then
cat | socat - tcp-listen:9000,reuseaddr | sed -r 's/(.*)/< \1/'
else
exec 3<>/dev/tcp/"$1"/9000
{
while read -r -u 3 line
do
echo '< ' "$line"
done
} &
while read -r myline
do
echo "$myline" >&3
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment