Skip to content

Instantly share code, notes, and snippets.

@doitian
Last active September 21, 2020 11:06
Show Gist options
  • Save doitian/5066622 to your computer and use it in GitHub Desktop.
Save doitian/5066622 to your computer and use it in GitHub Desktop.
Open unblocking FIFO on specified fd in zsh
#!/usr/bin/env zsh
set -e
[ -e /tmp/test.fifo ] || mkfifo /tmp/test.fifo
# open the FIFO on fd 3 without blocking
exec 3<> /tmp/test.fifo
zmodload zsh/zselect
if zselect -r 3; then
read -t 0 line <&3
echo "$line"
fi
# Run in another terminal:
#
# echo 123 > /tmp/test.fifo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment