Pseudoportable C script pattern - follow-up See the initial/previous iteration. 

I have rewritten the script following the answer of @200_success.

Now it looks like this:

#! /bin/bash

# Create a temporary file name for the executable file:
TMP_PROGRAM_FILE="$(mktemp programXXXXXX)"

# Compile the embedded C program:
gcc -o "$TMP_PROGRAM_FILE" -x c - &lt;&lt;- END_OF_SOURCE
#include &lt;stdio.h&gt;

int main(int argc, char* argv[]) 
{
    int i;

    puts("Hello, world! I am a pseudoportable C program.");
    for (i = 1; i &lt; argc; ++i) 
    {
        printf("Argument %d: %s\n", i, argv[i]);
    }

    return argc - 1;
}
END_OF_SOURCE

# Run the program delegating all the arguments:
./$TMP_PROGRAM_FILE $@

# Save the exit status of the C program:
EXIT_STATUS=$(echo $?)

# Remove the executable file:
trap "rm $TMP_PROGRAM_FILE" EXIT

# Exit returning the exit status of the C program:
exit $EXIT_STATUS


Any critique much appreciated.
It can be made even simpler, by arranging for the C program to remove itself when it runs:

#! /bin/bash

# Create a temporary file name for the executable file:
TMP_PROGRAM_FILE="$(mktemp programXXXXXX)"

# Compile the embedded C program:
gcc -o "$TMP_PROGRAM_FILE" -x c - &lt;&lt;- END_OF_SOURCE
#include &lt;stdio.h&gt;
#include &lt;unistd.h&gt;

int main(int argc, char* argv[]) 
{
    int i;

    puts("Hello, world! I am a pseudoportable C program.");
    for (i = 1; i &lt; argc; ++i) 
    {
        printf("Argument %d: %s\n", i, argv[i]);
    }
    unlink("$TMP_PROGRAM_FILE");
    return argc - 1;
}
END_OF_SOURCE

# Run the program delegating all the arguments:
./$TMP_PROGRAM_FILE $@


This will not work under Windows but does work under Linux.  I haven't tested Mac, but believe it will work there, too. The change, of course, is that the C program now deletes itself.