Last active
September 21, 2020 11:06
-
-
Save doitian/5066622 to your computer and use it in GitHub Desktop.
Open unblocking FIFO on specified fd in zsh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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