41 points · by alcover · 6y ago · 47 comments
Couple of immediate issues with the repo:
- Sample output in the README should not be prefixed with a "$". That's only for the shell command prompt.
- Use ``` blocks in your README file. It's easier to format multi-line text.
- Don't use $RANDOM, it's not secure. Use mktemp: https://github.com/alcover/runc/blob/73aaecea5a4cd357f7172dd...
- Don't exit with success if the command failed: https://github.com/alcover/runc/blob/73aaecea5a4cd357f7172dd...
- Use Bash strict mode: http://redsymbol.net/articles/unofficial-bash-strict-mode/
You can get saner splitting for that loop over the array by quoting the array expansion:
for name in "${names[@]}"
Shellcheck lints that, by the way.I need a little time to study your 'strict mode' suggestion. I used 'set -e' before but had problems with it.
Would you know how I could detect that input is cat'ed into the script ? ($ cat snippet.c | runc -i). So that I can suppress 'Type your code then CTRL+D'.
Stack Overflow suggests http://stackoverflow.com/questions/10022323/ddg#10022396
Again, it's not the project name just the potential clash at the OS level. Because over the years, I've done it to myself.
I admit I didn't research the name 'runc'.
Should I rename it ? I like this one because it's short and explicit.
As a bonus, it can output "I don't like C code, I love it" in its help/version docs.
People could #!bin/bash it however they want.
I only noticed the clash because "runc" seemed familiar.
See also Cling, an interactive C++ interpreter.
//$(which gcc) $0 -o a.out; ./a.out $@; rm a.out; exitDoes not work in the spirit of my script though, since you would still need to add headers and main():
//$(which gcc) $0 -o a.out; ./a.out $@; rm a.out; exit
int i = 10;
printf ("%d\n", i);
./snip.c:3:9: error: expected declaration specifiers or ‘...’ before string constant
printf ("%d\n", i);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 wrote this for a hackathon, so please excuse the messy code :)
gcc main.c && ./a.out