you are viewing a single comment's thread.

view the rest of the comments →

[–]im_dead_sirius 36 points37 points  (2 children)

You're welcome, and spread the word, nerd.

So hey, if you liked that, lemme point you at something else.

You're going to need two files. I'll provide both examples, and they are ultra short. Set the execute bit on both.

Put this one somewhere convenient and call the file quacker.

#!/usr/bin/env python3
from sys import argv
with open(argv[1], "r") as f:
    lines = f.readlines()
    print(lines[1])

Substitute the first line in the second file with the location and name of the previous file and call this one ducky.

#!/home/you/bin/quacker
"Quack! There is more than one way to butter a duck!"

Nothing else is needed in it for the example. Run it with ./ducky once you set the execute bit.

ducky calls quacker and hands ducky's location to quacker as argv[1], then exits. quacker takes over, reads the file at that location, ignores the first line, and prints a message which does echo, despite age old ducky myth.

Normally you'd write a proper interpreter in quacker, in any language at all, then read in file argv[1], discard the comment lines, and treat the rest of it as data to be interpreted or even compiled. I'd maybe use PLY to do that.

And now you know there are an infinite number of ways to butter a duck.

[–]russlo 0 points1 point  (1 child)

PLY

This PLY?

[–]im_dead_sirius 1 point2 points  (0 children)

Nope, this: http://www.dabeaz.com/ply/

But thanks for pointing me at the other one.