Last active
October 11, 2022 22:54
-
-
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
This file contains hidden or 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 | |
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