I have been writing system administration scripts for a couple of years now, first with just regular Bash and later Python. In terms of bash scripting, I have to admit that while my invocations of my favorite tools, such as sed and find, have become more complicated my use of shell scripting programming statements has remained pretty basic. I don’t write shell scripts on a daily basis so in the weeks between writing scripts I manage to re-forget how to write a proper for loop and how to use getopts.
Setting up narwhal
$ git clone git://github.com/280north/narwhal.git
You should append the following text to your .bashrc file and then open a new terminal
Run “narwhal” or “js” (they are equivalent).
$ sudo aptitude update $ sudo aptitude install sun-java6-jdk # alternately, sun-java5-jdk
You may want to remove the extra lines from your sources.list after you have finished installing the package.
Next you may need to tell Ubuntu explicitly to use Sun’s JDK
$ sudo update-alternatives —config java # There are at least 2 alternatives which provide `java’. Selection Alternative + * 1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 2 /usr/lib/jvm/java-1.5.0-sun/jre/bin/java Press enter to keep the default[*], or type selection number: # Choose #2
To test your install just run narwhal from the command line
you@computer:/$ narwhal Rhino 1.7 release 3 PRERELEASE 2009 12 12 js> print("hello") hello js>
We can run our little “Hello World” as a script
// hello.js print('hello world');
$ narwhal hello.js
Narwhal has a number of command line options which you can list with
A Note on Narwhal Engines
$ tusk install narwhal-jsc $ cd packages/narwhal-jsc $ make # or "make webkit" if you want to use the jsc context from a webkit instance, # and thus have access to the DOM and other APIs
From here on, you can run narwhal-jsc by simply running “narwhal-jsc” or you can make it your default engine for narwhal by adding
NARWHAL_ENGINE=jsc in your .bashrc or whatever file you use to control your bash shell settings.
That’s it for now, stay tuned for a tutorial on Jake, a rake clone. If you aren’t familiar with make or rake, they are excellent tools for automating repetitive administration tasks.