Read named pipe once every time input is written
In your case, you can do simply:
tail -f $pipe | sh &
no need for loops.
One way to do it:
#! /usr/bin/env bash
pipe=/path/to/pipe
[ -p "$pipe" ] || mkfifo -m 0600 "$pipe" || exit 1
while :; do
while read -r cmd; do
if [ "$cmd" ]; then
printf 'Running %s ...\n' "$cmd"
# sh -c "$cmd" sh
fi
done <"$pipe"
done
It's probably a really bad idea to uncomment the sh
line though.