Scripting languages are found all over your Linux system. From Python to Shell, from Ruby to Haskell, there are so many flavours of scripting language that to choose just one would be the height of boring distaste. Over the coming few articles, I shall endeavour to show you the basics of a number of scripting languages, but in order to keep things short and sweet, I shall limit myself to three languages - that of Lua, Perl, and Python.
A REPL (Read-Evaluate-Print-Loop) is essentially exactly what the shell is. It is a style of user interface where a program prompts for input, reads that in, evaluates it there and then, prints the result out, and then loops back to prompting for new input. Each of Lua, and Python have REPLs; where Perl simply reads a program from standard input when you run the language interpreter with no other arguments.
Lua's REPL looks like this:
Lua 5.3.1 Copyright (C) 1994-2015 Lua.org, PUC-Rio >
Python's more like this:
Python 3.4.2 (default, Oct 8 2014, 10:45:20) [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
However, since Perl has all the tools known to man, if you install
libdevel-repl-perl package on Debian and derivatives) you
can simply run
re.pl and get the following very perly prompt:
In all three cases, pressing Control+D will exit the repl (providing you enter that on an otherwise blank input line), but you can also use (for Lua):
>>> import sys >>> sys.exit(0)
$_ exit 0
Now, despite their various roots, scripting languages often share some very simple syntax between them. Though depending on the origin of the language the specifics might vary. For today we're just going to look at the simplest of commands -- writing some output to stdout.
For Lua, there is a function called
> print("Hello World", 1+5) Hello World 6 >
>>> print "Hello World", 1+5 Hello World 6 >>>
As you can see, Python added a single space rather than a tab. Perl's a little
more text-oriented by default though, and its
$_ print "Hello World ", 1+5, "\n" HelloWorld6 $_
For this week, I ask that you pick a scripting langauge, either one of the
above or any other you fancy, and spend some time getting used to the REPL
for it. Practice using the