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
    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 '18 at 9:56
  • but telnet terminates due to no stdin instead of no stdout, no? – pepero Feb 2 '18 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.