0

with

#!/bin/bash
telnet ipaddr port &

i=1
while [ "$i" -lt 3 ]
do
   (( i += 1 ))
   sleep 10
done

result:

Trying ipaddr... Connected to ipaddr. Escape character is '^]'. Connection closed by foreign host

fine, since bash scripts run in non interactive, so no stdin used, telnet close immediately.

however if I add tee to redirect the result, like

telnet ipaddr port | tee -a out.txt &

the telnet service could run and get output. but what is the difference tee made? i expect the telnet will terminate immediately as well.

2
  • 2
    Handwaving: I believe it's due to the pipe, not tee specifically. Without the pipe, telnet doesn't have a proper stdout, but it has with the pipe.
    – Kusalananda
    Feb 2, 2018 at 9:56
  • but telnet terminates due to no stdin instead of no stdout, no?
    – pepero
    Feb 2, 2018 at 14:35

0

You must log in to answer this question.

Browse other questions tagged .