Skip to content

Instantly share code, notes, and snippets.

@rlcamp
Last active October 11, 2022 22:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlcamp/0b19a9a4d86d0a497c04ae8880d95b21 to your computer and use it in GitHub Desktop.
Save rlcamp/0b19a9a4d86d0a497c04ae8880d95b21 to your computer and use it in GitHub Desktop.
for when you really just need to run a bit of C logic from a bash script
#!/bin/bash
TMPFILE=$(mktemp)
cc -Wall -Wextra -Wshadow -Os -lm -o ${TMPFILE} -x c <(tail -n+$(awk '/^exit$/ { print NR + 1 }' $0) $0) && chmod +x ${TMPFILE} && ${TMPFILE} "$@"
rm ${TMPFILE}
exit
#include <stdio.h>
#include <unistd.h>
int main(const int argc, const char ** const argv) {
fprintf(stderr, "hello world\n");
for (int iarg = 1; iarg < argc; iarg++)
fprintf(stderr, "argument %d is %s\n", iarg, argv[iarg]);
fprintf(stderr, "stdin is %sa tty\n", isatty(STDIN_FILENO) ? "" : "not ");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment