title: How to get telnet execution result code from shell script?
body: <p>Using the following shell code for remote telnet request:</p>
  
  <pre><code>{
  sleep 5
  echo admin
  sleep 3
  echo pass
  sleep 3
  echo ls
  sleep 5
  echo exit
  } | telnet 172.16.1.1
  </code></pre>
  
  <p>I want to check if telnet connection was successful or not. Trying to use $?:</p>
  
  <pre><code>echo $?
  </code></pre>
  
  <p>But it always returns "1", even if telnet connection was OK.</p>