title: Linux - even using exit command, it pass result to pipe
body: <p>I am writing a script, which find the max length of line in all files and directories(with FIND), I get names of files as script arguments.
  I have while loop which goes through all files and print longest line from each. After this while loop goes through all arguments, there is a PIPE that passes these results to awk which should just pick the longest one and print it.
  <strong>This is code:</strong><br></p>
  <pre class="lang-sh prettyprint-override"><code>{ while [ ! $# -eq 0 ]; do
      if [ -f &quot;$1&quot; ]; then    
          awk -v name=&quot;$1:&quot; ' {
              if ( length &gt; ln ) 
              { ln=length ;content[i=1]=$0 ;line[i]=NR } 
              else if ( length == ln )
              { content[++i]=$0 ; line[i]=NR }
          }
          END{ for(j=1;j&lt;=i;j++) print name, line[j], ln, content[j] }' &quot;$1&quot;
      
      elif [ -d &quot;$1&quot; ]; then
          mapfile -d '' files_arr &lt; &lt;(find &quot;$1&quot; -type f \( -name &quot;*[[:space:]]*&quot; -o -name &quot;*&quot; \) -perm -a=r -print0)  
          for i in &quot;${files_arr[@]}&quot;; do
              awk -v name=&quot;$i:&quot; ' {
              if ( length &gt; ln ) 
                  { ln=length ;content[i=1]=$0 ;line[i]=NR } 
              else if ( length == ln )
                  { content[++i]=$0 ; line[i]=NR }
              }
              END{ for(j=1;j&lt;=i;j++) print name, line[j], ln, content[j] }' &quot;$i&quot;
          done
      else
          echo &quot;Error: '$1': File like this doesnt exist.&quot; &gt; /dev/stderr
          exit 2
      fi
      shift
      done
  } | awk ' { if ( $3&gt;max ) { max=$3 ; result[i=1]=$0 } else if ( $3==max ) { result[++i]=$0 } } 
  END{ for(j=1;j&lt;=i;j++) print result[j] } ' 
  </code></pre>
  <br>
  The problem is, when I have file, which doesnt exist as 2. argument, then I would like to print error message and exit, but my script print error and also print results from previous script argument (f.e. first argument).
  <br>
  Thank you once again for your help!