JSTalk Shell Scripts

Daniel Jalkut / @danielpunkass:

@rentzsch Can you please write a bug: “FastScripts is too good.” ?

Daniel Jalkut / @danielpunkass:

@rentzsch Currently scratching my head as to how FastScripts is running your .jstalk ;)

I tweeted back at Jalkut, but I probably should document the magic here as well.

※ ※ ※

  1. Install the jstalk command-line tool:

    • http://jstalk.org and download the .zip file
    • sudo cp jstalk /usr/local/bin
    • Create your .jstalk script:

      echo "print('hello jstalk')" > hello.jstalk

  • Test to make sure it works:

    $ jstalk hello.jstalk
    hello jstalk
    
  • Now engage standard Unix magic to make a script executable. Just use your fav editor to insert this line at the top of your script:

    #!/usr/local/bin/jstalk
    

    Your script should now look like this:

    #!/usr/bin/local/jstalk
    print('hello jstalk')
    

    Here’s a shortcut if you just want to prepend the line without firing up your editor:

    $ echo '#!/usr/local/bin/jstalk'|cat - hello.jstalk|tee hello.jstalk
    

    jstalk knows to ignore the new shebang line even though it’s invalid JavaScript:

    $ jstalk hello.jstalk 
    hello jstalk
    
  • Flip on the script’s executable bit:

    $ chmod u+x hello.jstalk
    

    Now the script is executable directly:

    $ ./hello.jstalk
    hello jstalk
    

Hint: nothing really special about JSTalk here — this works with all Unix scripting languages like perl, ruby, python and even node.js.

jstalk Dec 1 2010