Skip to content

Instantly share code, notes, and snippets.

@CRTified
Last active February 6, 2018 19:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save CRTified/de7da2976a3b4e7f3f66403797655e2e to your computer and use it in GitHub Desktop.
Save CRTified/de7da2976a3b4e7f3f66403797655e2e to your computer and use it in GitHub Desktop.
Shebangs
#!/usr/bin/env sh
#if 0
TMPFILE=$(mktemp);
tail -n +10 $0 | gcc -march=native -o $TMPFILE -x c -;
$TMPFILE "${@:1}";
RETVAL=$?
rm $TMPFILE;
exit $RETVAL;
#endif
#include<stdio.h>
int main(int argc, char* argv[])
{
printf("Hello world, I live at %s\nMy params are:\n", argv[0]);
for(int i = 0; i < argc; i++)
{
printf("argv[%u] = %s\n", i, argv[i]);
}
return 0;
}
// $ ./shebang.c foo bar baz
// Hello world, I live at /tmp/tmp.r0QcpfUSUv
// My params are:
// argv[0] = /tmp/tmp.r0QcpfUSUv
// argv[1] = foo
// argv[2] = bar
// argv[3] = baz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment