I’m new to bash script programming and I’m trying to understand the code below:
<code>tmp_file=/tmp/tmp_file$$
mkfifo $tmp_file
echo "msg_A" >$tmp_file # blocks, since pipe is unbuffered and no one is reading from it
read msg <$tmp_file
echo $msg
</code>
<code>tmp_file=/tmp/tmp_file$$
mkfifo $tmp_file
echo "msg_A" >$tmp_file # blocks, since pipe is unbuffered and no one is reading from it
read msg <$tmp_file
echo $msg
</code>
tmp_file=/tmp/tmp_file$$
mkfifo $tmp_file
echo "msg_A" >$tmp_file # blocks, since pipe is unbuffered and no one is reading from it
read msg <$tmp_file
echo $msg
<code>tmp_file=/tmp/tmp_file$$
mkfifo $tmp_file
exec 7<>$tmp_file # add this line
echo "msg_A" >$tmp_file # now, the write operation won't block, why?
read msg <$tmp_file
echo $msg # msg_A is printed
</code>
<code>tmp_file=/tmp/tmp_file$$
mkfifo $tmp_file
exec 7<>$tmp_file # add this line
echo "msg_A" >$tmp_file # now, the write operation won't block, why?
read msg <$tmp_file
echo $msg # msg_A is printed
</code>
tmp_file=/tmp/tmp_file$$
mkfifo $tmp_file
exec 7<>$tmp_file # add this line
echo "msg_A" >$tmp_file # now, the write operation won't block, why?
read msg <$tmp_file
echo $msg # msg_A is printed
I want to know what does exec 7<>$tmp_file
do in the code example above, and why adding this line makes the write operation non-blocking?
1