This is definitely helpful for testing.
Also related is the tiny C compiler and its `tcc -run` command.
Also related is the tiny C compiler and its `tcc -run` command.
#!/usr/bin/tcc -run
#include <stdio.h>
int main() {
printf("Hello\n");
return 0;
} tcc -w -run - <<< 'main() { printf("Hello\n"); return 0; }'
However, runc seems more convenient to pass in just the statements.If you want to make `tcc -w -run` etc. more convenient then:
alias trun='tcc -w -run - <<<'
trun 'main() { printf("Hello\n"); return 0; }'
---I can't edit my parent comment now, but it can be improved with e.g.
//usr/bin/tcc -run $0; exit
main() { printf("Hello\n"); return 0; }I know, but the first example in the link was:
$ runc 'printf("%s\n", "Hello!");'
Hello!
So I figured I'd complement your example use with one that was more analogous to that.> I can't edit my parent comment now, but it can be improved with e.g.
To be honest, I liked your original example more. Using that `//` "shebang" depends on what shell it's invoked from, and it wouldn't work when calling exec from other languages. For example, with your last example using `//`:
$ python -c 'import subprocess; subprocess.run(["./hello-tcc-double-slash-shebang.c"])'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.8/subprocess.py", line 489, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: './hello-tcc-double-slash-shebang.c'
while it would work with the `#!` shebang, since that's handled by the kernel.