Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 890 Bytes

README.rst

File metadata and controls

39 lines (28 loc) · 890 Bytes

turnout-for-what

image

Usage

tfw SWITCH
SWITCH

A file descriptor yielding a stream of line-separated paths. For every line received from stdin, the last path received from SWITCH indicates the file that the line should be redirected to.

Example

A load-balancer for the natural numbers:

#!/usr/bin/env bash

trap "rm -f nat {0..4}; pkill -P $$" EXIT

touch nat {0..4}

while true; do
  echo $((i++))
  sleep 0.2;
done > nat &

tail -f nat | cargo run -- <(tail -f nat | xargs -I{} expr {} % 5) &

while true; do
  sleep 0.2
  clear
  wc -l {0..4}
done

This script will create five text files, balance the natural numbers between them, and continuously print their line counts.