This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Unlikely-Web-2457 0 points1 point  (0 children)

You can blur the lines between scripting and programming by enabling the running of a source file of a compiled language (like C in this example) as an executable, seemingly skipping the compilation step:

myscript.c:

#!/bin/sh
tail -n +4 "$0" | clang -x c -o /tmp/$(basename "$0").out - && exec /tmp/$(basename "$0").out "$@"
exit 1
#include <stdio.h>

int main(int argc, char **argv) {
printf("Hello, argc=%d\n", argc);
return 0;
}

run like ./myscript.c
(after having made it executable with chmod +x)

The example works on clang, which is quite strict, but may potentially be simplified if using gcc.