#!/bin/bash PORT=12345 # For every input line while IFS= read -r payload; do # For every character for (( i=0; i<${#payload}+1; i+=1 )); do char="${payload:$i:1}" if [[ "$char" == "1" ]]; then timeout 1 nc -lp "$PORT" >/dev/null else sleep 1 fi done done