title: "telnet" command fails with "bad port" when executed in shell script, but works on command prompt
body: <p>This is probably really simple. I am logging into a remote server using PuTTY and running a <code>telnet 12.34.56.789 22</code> command to test TCP connections on port 22. </p>
  
  <p>This works fine when I type the command manually, but I have a range of destinations to check and I thought it would be better to use a script for this. I created a very basic shell script which is just a list of the commands I want to run one after another. When I run this script from PuTTY I get an error saying </p>
  
  <blockquote>
    <p>: bad port</p>
  </blockquote>
  
  <p>Can anyone explain to me why the command works when I type it manually, but produces an error when I run the script?</p>
  
  <p>Script:</p>
  
  <pre><code>telnet 10.52.33.46 22  
  telnet 10.52.33.47 22  
  telnet 10.52.33.48 22  
  telnet 10.52.33.49 22  
  telnet 10.52.33.50 22  
  telnet 10.52.33.51 22  
  telnet 10.52.33.52 22  
  telnet 10.52.33.53 22  
  telnet 10.52.33.54 22  
  telnet 10.52.33.55 22
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/7x9SQ.png" rel="nofollow noreferrer">Here is a screenshot of the PuTTY window with the error message. I save the above script (159999.sh) onto the host server, then run it from there.
  </a></p>
  
  <p><a href="https://i.stack.imgur.com/OLFaT.png" rel="nofollow noreferrer">Here is some of the commands running after I type them manually (in this case they are supposed to fail to connect)</a></p>