title: Getting the output from first command to exit in Bash
body: <p>Suppose I have a Bash script that takes one parameter (ie. port number) and performs some logic with either outcome </p>
  
  <ol>
  <li>hangs for 1 second and exits with timeout error, or</li>
  <li>succeeds within milliseconds and outputs a message such as "ON" or "OFF".</li>
  </ol>
  
  <p>One way to find the parameter that results in outcome 2 would be run the script over loop on the possible values of the parameter, but this would take N seconds to find the parameter. Assume the output is consistent for simplicity (ie. if more than one instance results in outcome 2,  their output message is the same).</p>
  
  <p>Is there a way to run the N instances of the Bash script at the same time (within reasonable milliseconds) with each possible value of the parameter, and get the output message from the instance that finished fastest? This would result in getting the output in under 1 second.</p>