5 ms·
Not exactly a polyglot script, but a while back I had to work on a cluster whose job management system always ran everything as shell scripts. Or rather, it had
by rcthompson 7y ago
Not exactly a polyglot script, but a while back I had to work on a cluster whose job management system always ran everything as shell scripts. Or rather, it had to be run as a shell script in order to set the right cluster options. I wanted to submit an R script, so what did I do? I wrote a file that was both a bash script and an R script. When run as an R script, it does what I want it to do. When run as a bash script, it runs itself as an R script (after setting the cluster options). Problem "solved".
Here is is, if anyone's interested: https://gist.github.com/DarwinAwardWinner/2eb3705fb6ddab08ee47 https://gist.github.com/DarwinAwardWinner/2eb3705fb6ddab08ee...
And here's the Python version: https://gist.github.com/DarwinAwardWinner/8a631d897d45f005528a https://gist.github.com/DarwinAwardWinner/8a631d897d45f00552...
- ErotemeObelus 7y agoVery clever. But this kind of behavior made habitual will get you the reputation of a dirty hacker.
- fwip 7y agoWouldn't it have been easier to submit: #!/bin/bash Rscript myscript.R
- shakna 7y agoThey may have only been able to submit the single file to the system. (In which case I would have generated the Rscript to a tmpfile, but maybe that wasn't allowed either.)
- rcthompson 7y agoNo, I totally could have written a separate R script that was then run by the bash script. I just wanted to have it all in one file, and I thought it was a fun challenge figuring out how to do it.
- niedzielski 7y agoI've been collected hacks for a couple languages and tools here: https://git.io/shebang https://git.io/shebang
- rcthompson 7y agoI think the difference with mine is that I actually need to squeeze some shell code in there as well, to set up the cluster environment before "handing off" to R/Python.