Skip to content

Instantly share code, notes, and snippets.

@bartman
Last active January 9, 2023 20:25
Show Gist options
  • Save bartman/8b3bcc0a2431678d64d2bfb4849c02a5 to your computer and use it in GitHub Desktop.
Save bartman/8b3bcc0a2431678d64d2bfb4849c02a5 to your computer and use it in GitHub Desktop.
run C file as a script, complied with any compiler
#!/bin/bash
#if 0
set -e
src=$0
tmp=/tmp/$$.cpp
exe=/tmp/$$
sed -e 1d < $src > $tmp
trap "rm -f $tmp $exe" EXIT
( set -x ; g++ -o $exe $tmp )
$exe "$@"
exit $?
#endif
#include <stdio.h>
int main()
{
printf("hello word\n");
}
@bartman
Copy link
Author

bartman commented Jan 9, 2023

$ ./shell.cpp
+ g++ -o /tmp/3789385 /tmp/3789385.cpp
hello word

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment