在这种情况下,为什么分配位置会导致无限循环?

有人可以弄清楚为什么以下分配的位置引起无限循环吗?

我正在编写一个测试程序来测试管道,该管道使用此脚本在2个终端上运行,而第三个终端仅回显pipe1和pipe2。如果我在IF条件之后放置 received =“ $ input” ,那么结果是两个终端上的无限循环。但是,如果将此作业放在末尾,效果会很好吗?

#!/bin/bash 

received="null"
while true; do
        read input < "$1" #this is either pipe1 or pipe2
        if [ "$input" != "$received" ]; then
                echo "$input"
                echo "$input" > "$2" #again,either pipe1 or pipe2
                received="$input"
        fi
done

在1号航站楼,我跑:

./r_w_test.sh pipe1 pipe2

然后在2号航站楼中运行:

./r_w_test.sh pipe2 pipe1

然后在第三个终端中运行:

echo "hi" > pipe1 

等等等。

为什么在此处放置作业时出现无限循环:

...
if [ "$input" != "$received" ]; then
        received="$input"
        echo "$input"
        echo "$input" > "$2"
...
leiximo 回答:在这种情况下,为什么分配位置会导致无限循环?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3121131.html

大家都在问