Simple Task Queue in Shell Jan. 18, 2026

Useful for software building automation.

Features

The Script

#!/bin/sh
exec 2>&1
[ -r ./conf ] && . ./conf

q="${queue:-$HOME/queue}"
[ -p "$q" ] || mkfifo "$q" || exit 1
[ -p "$q." ] || mkfifo "$q." || exit 1

sh <<EOF &
exec 3>"$q."
while :; do
  cat <"$q" >&3
done
EOF

exec 3<"$q."

while :; do
  IFS= read -r line <&3 || break
  sh -c "$line" &
  echo "[$!] $line"
  wait $!
done

You can run it with any process supervisor in the background.

The script is in Public Domain.

Usage

Basic

cd $HOME
echo "sleep 10" >queue
echo "env -C /opt/code/my-go-code go build" >queue

The echos complete instantly; the tasks will run one-by-one.

Advanced

#!/bin/sh
exec 3>$HOME/queue
cd /opt/code
for i in $(ls); do
  echo "exec env -C /opt/code/$i make" >&3
done
exec 3>&-

It’s best to open and close the queue FIFO only once.