Q: Unix return status for system (echo..) suspected We have a job that runs a Perl script which prepares 3 files (Header, content, Footer) and later-on merges them into one file.
Header file preparation using system command 
$ret = system("/usr/bin/echo '$hdr' > $HDR_FILE");
if ( $ret != 0 )
{
   print STDERR "**ERROR** error preparing header\n";
}

Merger File command is as below
  $ret = system("/usr/bin/cat $HDR_FILE $CONTENT_FILE $TRLR_FIL > $OUTPUT_FILE");
    if ( $ret != 0 )
    print STDERR "**ERROR** merge failed\n";

During the latest execution of the job we don't see any traces of the header errors but still final output file $OUTPUT_FILE did not have the header while content and trailers were present.
can
$ret = system("/usr/bin/echo '$hdr' > $HDR_FILE");

return '0' status even when the header file was empty?

A: I would simplify your code with better error handling:
Option 1: Use backtick
$ret = `/usr/bin/echo '$hdr' > $HDR_FILE 2>&1`;
if ( $? || $ret )
{
   print STDERR "**ERROR** error preparing header, error: $ret\n";
}

Option 2: Use print instead of echo
open(my $fh,'>',$HDR_FILE) or die "Cannot write to $HDR_FILE";
print $fh $hdr;
close($fh);

