Non interactive execution


Marie-Hélène Burle

Sourcing a file

Julia scripts have a .jl extension.

The include function sources a Julia script (in a REPL session or in another script):


The code contained in file.jl is thus run non interactively.

Running code from the command line

You can run scripts by passing them to the julia command on the command line:

$ julia script.jl

This code is run in a terminal, not in Julia, as is indicated by the $ prompt.

You can also evaluate single expressions in Julia from the command line by using the flag -e:

$ julia -e 'println(2 + 3)'

Passing arguments

To the julia command itself

If you want to pass arguments to the julia command itself, you need to add them before the script or the Julia expression.


$ julia -O script.jl

To the script/Julia expression

To pass arguments to the script (or Julia expression if you use -e), you add them after the script or expression:

$ julia script.jl arg1 arg2 arg3

arg1, arg2, arg3 will be passed in the global constant ARGS and interpreted as arguments to the script.

Example passing arguments to an expression:

$ julia -e 'for x in ARGS; println(x); end' 2 3

To both

To pass arguments both to the julia command and to the script/expression, you need to add the -- delimiter before the script/expression:

$ julia [switches] -- [programfile] [args...]


$ julia -O -- script.jl arg1 arg2