Skip to content

Instantly share code, notes, and snippets.

@detomon
Last active July 23, 2017 14:40
Show Gist options
  • Save detomon/e04734c2890fd51b18e3f2109248ec4c to your computer and use it in GitHub Desktop.
Save detomon/e04734c2890fd51b18e3f2109248ec4c to your computer and use it in GitHub Desktop.
Compiling and running a C program in the shell by executing itself as shell script
#if 0
clang -Wall -O2 -o /tmp/`basename $0` $0 && /tmp/`basename $0` $@; exit
#endif
//
// sh run-in-shell.c `whoami`
//
#include <stdio.h>
int main(int argc, char const* argv[]) {
printf("Hello, %s!\n", argv[1]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment