Tuesday, December 16, 2008

A disappointing bit of UNIX trivia

So here is something I discovered today, in the course of other pursuits.

As you all may or may not know, every script in a UNIX environment begins with a "#!", followed by the name of the program that should be used to run the script. This feature was added in the early '80s to allow for alternate shells, along with increased portability and a few other benefits. With this, you can run a script as though it were an executable binary, and the system will handle all the messy stuff for you behind the scenes.

Fast-forward to today, where I'm writing my latest project. (More on this project when it's somewhat complete and usable.) I have this program, which takes a data file as an argument. It struck me while I was in the shower (I have a lot of good ideas in the shower!) that it'd be really useful to have the data file executable as a script itself, using the #! syntax. So I try it, and lo and behold, it... fails horribly. Tried it again slightly differently, and another failure.

When things fail inexplicably, I do what any good geek does, and turn to the Internet! A bit of quick googling leads me to the Wikipedia page, which is informative but not terribly helpful. Going a little further, I end up on this page, which has a lot of arcana about history and portability, along with this little tidbit:

"In practice, env must not be a script, because the #! mechanism only accepts binary executables (except on very few implementations like UWIN and Minix)."

Unfortunately, my interpreter is itself a script, so it looks like that particular idea was doomed from the beginning. :( If it works out, though, I'm planning to rewrite this particular project in C, so maybe it'll work out someday.

3 comments:

Kiriska said...

My only comment:

FACT: All the best ideas come when you're in the shower.

Anonymous said...

Æther desires a post in which he understands what you're talking about. :(

Also: Your desktop may be online, but mine is still in the shop getting three fans replaced. :(:(:(

Solution: Create some viable solid state heat syncs to make my entire computer not need fans. Gogogo.

Anonymous said...

Um, what Kiriska and Aether said. (goes back to textual criticism in Propertius ugh)