Running JavaScript Shell Script from JSDB
In this tutorial, we take a look at another interactive JavaScript interpreter called JSDB to run JavaScript shell scripts.
Download the zip package from http://www.jsdb.org/download.html (the one without ODBC should suffice for the purpose here).
Extract the downloaded zip file. You will get the JSDB executable file, which is the JavaScript interpreter.
Next, navigate to the directory where the extracted
jsdb executable file is located. Open a
text editor and insert the below shebang interpreter directive and
save the file (as say, hello.js) in the
same location
#!jsdb
Add the command
writeln("Hello, World!"); after the
shebang directive to print "Hello, World"
#!jsdb
writeln("Hello, World!");
Next, we make the hello.js file executable
chmod u+x hello.js
Finally, we run the script file typing the command
./hello.js
Notes
-
The
jsdbinterpreter can be moved to the/usr/binfolder and likewise change the path in the shebang directive to#!/usr/bin/jsdb. -
If during execution of the script it gives error like
"jsdb: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory"in some Debian-based distributions (such as Ubuntu), install thelib32stdc++6package. -
Browser
Windowobjects likedocument,location,navigator,screen,historywill not work in JSDB.