Last active
November 28, 2015 09:24
-
-
Save coderodde/d8df70f859c80547f120 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 - <<- END_OF_SOURCE | |
#include <stdio.h> | |
int main(int argc, char* argv[]) | |
{ | |
int i; | |
puts("Hello, world! I am a pseudoportable C program."); | |
for (i = 1; i < 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment