让我向大家介绍一下我的循环:
\n\nNUM_LINE=0\nwhile read line; do\n let NUM_LINE+=1\n if [ $NUM_LINE -lt 41 ]; then\n echo -e "\\t$BLANC|$ORIGINAL $line $BLANC|"\n else \n echo -e "\\n\\t$BLANC## "$GRIS"Llista de Nodes sel\xc2\xb7leccionats $BLANC############$ORIGINAL\\n"\n read AUX\n NUM_LINE=0 \n fi\ndone <$NODES\nRun Code Online (Sandbox Code Playgroud)\n\n以便:
\n\n$BLANC 与\\033[1;37m
\n$GRIS 相同
\n$ORIGINAL 以及
\n$NODES 是包含很多行的文件的绝对路径,例如:
\n| 23127 myserver 98.194.263.29 |
问题:
在语句echo内部,else它被正确触发。\n但它的发生情况与read它被正确触发。\n但它与语句的
有什么建议吗?
\n循环无法正常运行的原因是因为在这两种情况下 read 都是从 stdin 读取。您需要打开文件的备用文件描述符并从文件描述符中读取。
\n\nexec 3<$NODES\nNUM_LINE=0\nwhile read -u 3 -r line; do\n (( NUM_LINE++ ))\n if (( NUM_LINE < 41 )); then\n echo -e "\\t$BLANC|$ORIGINAL $line $BLANC|"\n else \n echo -e "\\n\\t$BLANC## "$GRIS"Llista de Nodes sel\xc2\xb7leccionats $BLANC############$ORIGINAL\\n"\n read AUX\n NUM_LINE=0 \n fi\ndone\nRun Code Online (Sandbox Code Playgroud)\n