3 ms·
The thing that surprised me was that you can't write an interpreter in an interpreted language, at least not in obsd. It is possible if you jump through a few h
by somat 11mo ago
The thing that surprised me was that you can't write an interpreter in an interpreted language, at least not in obsd. It is possible if you jump through a few hoops but you can't directly call it.
An example: if you made a language in python
/bin/my_lang: #does nothing but pretend it does
#!/usr/local/bin/python3
import sys
print('my_lang args', sys.argv)
for line in sys.stdin:
print('invalid_line:', line)
my_script:
#!/bin/my_lang
line of stuff
another line of stuff
chmod u+x my_script
./my_script
Probably for the best, but I was a bit sad that my recursive interpreter scheme was not going to work.
Update: looks like linux does allow nested interpreters, good for them.
https://www.in-ulm.de/~mascheck/various/shebang/#interpreter-script https://www.in-ulm.de/~mascheck/various/shebang/#interpreter...
really that whole document is a delightful read.
- jolmg 11mo agoWorked for me, but the way you described it has issues: 1. You chmod my_script twice. 2. Did you chmod u+x /bin/my_lang too? Since you put it in /bin, are you sure the owner isn't root?, in which case your user wouldn't have execute permission. Try +x instead of u+x. 3. Do you have python in that path? Try `/usr/bin/env python` instead. 4. In case you expected otherwise, my_script wouldn't be passed through stdin. It's just provided as an argument to my_lang.
- somat 11mo agoI am on openbsd. which does not allow it, it looks like nested interpreters are s supported on linux. So my loss there.
- teo_zero 11mo agoWait... your interpreter reads from stdin. Shouldn't it read its first arg, instead?
- somat 11mo agoI think that was what I was trying to figure out, how the program was passed. but OpenBSD does not do nested interpreters, it looks like if I had tried Linux it would have worked.
- deleted 11mo ago[deleted]
- deleted 11mo ago[deleted]
- mbreese 11mo agoIIRC interpreters can also read their programs from stdin. Try piping a script to bash and see if it works. (Actually, this is how the `curl install.sh | bash` anti pattern works. )
- deleted 11mo ago[deleted]
- teo_zero 11mo agoIndependently of what the interpreter can do, it's #! that doesn't pass the file to it.