Bash CGI Upload File
Since your script has no content to return, a status code of 204 No Content would be more desirable than 200 Success.  For that, you should echo "Status: 204 No Content" (RFC 3875 Sec 6.3.3).  Also consider returning using status code 405 Method Not Allowed for anything other than a POST request.

$TMPOUT is a misnomer.  The file is not temporary at all — $TMPOUT.1 contains the final output of your script.

If your goal is to redirect the input to a file, discarding the first four lines, the last line, and the trailing newline of the penultimate line, you don't need to execute any external commands.  Bash is fully capable of doing all of the work itself.  The script isn't pretty, but I still find it easier to understand than copying the data back and forth, extracting lines here and there each time.

#!/bin/bash

case "$REQUEST_METHOD" in
  POST)
    (
        # Discard first four lines
        read &amp;&amp; read &amp;&amp; read &amp;&amp; read &amp;&amp;

        # Read and echo, buffering two lines
        read line1 &amp;&amp;
        read line2 &amp;&amp;
        while read nextline ; do
            echo "$line1"
            line1="$line2"
            line2="$nextline"
        done

        # Echo penultimate line with no trailing newline.
        echo -n "$line1"

        # Discard last line ($line2)
    ) &gt; hello

    echo 'Status: 204 No Content'
    echo
    ;;

  *)
    echo 'Status: 405 Method Not Allowed'
    echo
esac