Getting Started
For this brief introduction you have to open a javash session and try the examples. Let's start!
With javash you can combine system programs that uses stdout and stdin and joolets (cmdlets of javash) through pipes. Examples:
jash$ ls (joolet)
The object passed
through pipes is 'pobj' (PipedObject) and contains a list of objects.
-hrw- Tue May 13 15:09:33 CEST 2008 365 .project
-hrw- Sun May 11 19:24:49 CEST 2008 220 .classpath
d-rwx Thu May 22 14:29:52 CEST 2008 4096 CVS
--rw- Thu May 22 17:13:44 CEST 2008 56 TODO.TXT
--rw- Mon May 26 12:10:53 CEST 2008 25 launcher.bat
--rw- Thu May 22 15:56:25 CEST 2008 694 LICENSE.TXT
d-rwx Mon May 26 16:11:02 CEST 2008 4096 jooscripts
...
jash$ ls (joolet) | grep .TXT (native program)
/home/tuono/workspace/javash/TODO.TXT
/home/tuono/workspace/javash/LICENSE.TXT
jash$ ls (joolet) | grep .TXT | sort (native commands)
/home/tuono/workspace/javash/LICENSE.TXT
/home/tuono/workspace/javash/TODO.TXT
You can also save the result of a pipe for reuse it later. JavaSh can serialize pobj in binary, xml or pure text form. Examples:
jash$ sysinfo
Java Runtime: Java(TM) SE Runtime Environment
Java Version: 1.6.0_03-b05
Os Name: Linux
Os Version: 2.6.21.3-slh-smp-4
Os Arch: i386
User: tuono
jash$ sysinfo | >xml sysinfo.xml
jash$ <xml sysinfo.xml | objgrep 'Os Arch'
Os Arch: i386
Javash
(with the java 6 ScriptingEngines) supports scripting in many
languages, in inline or interactive mode, or it may serve as
an
interpreter for a script file.The default script language is Javascript but you can add many more languages (like groovy, jruby, jython and other).
Inline mode:
jash$ @ println("ciao"); @
ciao
jash$ @
>>> var count=5;
>>> while(count>0) {
>>> print("*");
>>> count--;
>>> } @
*****
jash$ ls | @
>>> ShellConsole.println(pobj.toString());
>>> @
/home/tuono/workspace/javash/.project
/home/tuono/workspace/javash/.classpath
/home/tuono/workspace/javash/launcher.sh
/home/tuono/workspace/javash/console
/home/tuono/workspace/javash/test
...
In last example you can see that inline script can be piped and can have access to shell classes (or modify pobj)... It's very cool, isn't it?
Interactive scripting is also possible. This is a scripting session with groovy:
jash$ scriptengine groovy
jash$ interactive
groovy>
groovy> println "hello world"
hello world
groovy> x = 1
groovy> println x*5
5
groovy> fullString = ""
groovy> orderParts = ["BUY", 200, "Hot Dogs", "1"]
groovy> orderParts.each {
>>> fullString += it + " "
>>> }
groovy> println fullString
BUY 200 Hot Dogs 1
groovy> exit
jash$
Ok, That's all folks! See joolets and scripting for more information about JavaSh, and whoami for info about the author...