You can use MiniScript on the command line, and even use it to write clean, readable shell scripts!
Download and unzip the appropriate binary for your system:
Then install it somewhere in your path. On Mac and Linux, /usr/local/bin/ is a standard choice.
miniscript command by itself invokes an interactive (read/eval/print) loop. You can enter any MiniScript expression, press Return, and immediately see the answer. This is handy for quick calculations or experimentation.
$ miniscript MiniScript v1.3 Apr 6 2019 > 2+2 4
You can also enter functions, loops,
if statements, etc.; when you have one of these open, the prompt changes from
>>> to indicate that more input is needed.
> for i in range(1,5) >>> print("Spam " * i) >>>
The code will be executed when the block closer (
end for in this case) has been entered.
To exit interactive MiniScript, press Control-D (i.e. terminate input) or enter
You can also invoke MiniScript with a single command (which could be multiple statements separated by semicolons), using the
-c option. MiniScript will execute that command and immediately exit.
$ miniscript -c 'print(2^12)' 4096
Or, you can execute miniscript with the path to a MiniScript script file. The script file will be executed, and MiniScript will exit when done. Note that in this mode, MiniScript skips the first line if it starts with "#!". This allows you to write shell scripts that can be executed directly.
#!/usr/local/bin/miniscript print("The current directory is: " + File.curdir) print("And my arguments are: " + shellArgs)
Command-line MiniScript has a few other command-line options; use
miniscript -? to see what they are.
|exit(resultCode=0)||quits the MiniScript session|
|input(prompt="")||prompts the user for input, and returns the entered string|
|shellArgs||returns command-line arguments given with script invocation, as a list; shellArgs is the script itself|
|File||module of file-related methods (see below)|
File returns a map that simply groups together a bunch of methods for manipulating files.
|File.curdir||returns the current working directory|
|File.setdir(path)||changes the current working directory|
|File.children(path)||returns list of files within the given directory|
|File.name(path)||returns the file name from the given path|
|File.parent(path)||returns the path to the directory containing the given path|
|File.child(parentPath, childName)||combines the given directory path and file name, returning path to the child|
|File.move(oldPath, newPath)||moves/renames a file|
|File.delete(path)||deletes a file|
|File.open(path, mode="rw+")||opens or creates a file; mode can be "rw+" (open for reading/updating, creating if it doesn't exist), or any standard fopen mode; returns a file handle object (see below)|
Finally, when you use
File.open to open a file, what you get back is a little object that allows for reading and writing from that file. This object has the following methods.
|.close||closes the open file|
|.isOpen||returns true if the file is open, false if closed|
|.write(s)||writes the given string to the file|
|.writeLine(s)||writes the given string, followed by a carriage return|
|.read||reads the rest of the file, returning it as a string|
|.readLine||writes the next line of the file|
|.atEnd||returns true at the end of the file, false otherwise|
We will be putting the source code for MiniScript core, as well as the command-line wrapper, up in a public GitHub repo this summer (2019). In the meantime, please be patient while we get our act together.