Command-line Interface
Using arguments inside scripts
When running a script using julia
, you can pass additional arguments to your script:
$ julia script.jl arg1 arg2...
These additional command-line arguments are passed in the global constant ARGS
. The name of the script itself is passed in as the global PROGRAM_FILE
. Note that ARGS
is also set when a Julia expression is given using the -e
option on the command line (see the julia
help output below) but PROGRAM_FILE
will be empty. For example, to just print the arguments given to a script, you could do this:
$ julia -e 'println(PROGRAM_FILE); for x in ARGS; println(x); end' foo bar
foo
bar
Or you could put that code into a script and run it:
$ echo 'println(PROGRAM_FILE); for x in ARGS; println(x); end' > script.jl $ julia script.jl foo bar script.jl foo bar
The --
delimiter can be used to separate command-line arguments intended for the script file from arguments intended for Julia:
$ julia --color=yes -O -- script.jl arg1 arg2..
See also Scripting for more information on writing Julia scripts.
Parallel mode
Julia can be started in parallel mode with either the -p
or the --machine-file
options. -p n
will launch an additional n
worker processes, while --machine-file file
will launch a worker for each line in file file
. The machines defined in file
must be accessible via a password-less ssh
login, with Julia installed at the same location as the current host. Each machine definition takes the form [count*][user@]host[:port] [bind_addr[:port]]
. user
defaults to current user, port
to the standard ssh port. count
is the number of workers to spawn on the node, and defaults to 1. The optional bind-to bind_addr[:port]
specifies the IP address and port that other workers should use to connect to this worker.
Startup file
If you have code that you want executed whenever Julia is run, you can put it in ~/.julia/config/startup.jl
:
$ echo 'println("Greetings! 你好! 안녕하세요?")' > ~/.julia/config/startup.jl
$ julia
Greetings! 你好! 안녕하세요?
...
Note that although you should have a ~/.julia
directory once you’ve run Julia for the first time, you may need to create the ~/.julia/config
folder and the ~/.julia/config/startup.jl
file if you use it.
To have startup code run only in The Julia REPL, use atreplinit
in startup.jl
:
atreplinit() do repl
# ...
end
Command-line switches for Julia
There are various ways to run Julia code and provide options, similar to those available for the perl
and ruby
programs:
julia [switches] -- [programfile] [args...]
The following is a complete list of command-line switches available when launching julia (a '*' marks the default value, if applicable; settings marked '($)' may trigger package precompilation):
Switch | Description |
---|---|
|
Display version information |
|
Print command-line options (this message). |
|
Uncommon options not shown by |
|
Set |
|
Start up with the given system image file |
|
Set location of |
|
Load |
|
Enable or disable Julia’s default signal handlers |
|
Use native code from system image if available |
|
Enable or disable incremental precompilation of modules |
|
Enable or disable usage of native code caching in the form of pkgimages |
|
Evaluate |
|
Evaluate |
|
Load |
|
Enable N threads; |
|
Integer value N launches N additional local worker processes; |
|
Run processes on hosts listed in |
|
Interactive mode; REPL runs and |
|
Quiet startup: no banner, suppress REPL warnings |
|
Enable or disable startup banner |
|
Enable or disable color text |
|
Load or save history |
|
Enable or disable syntax and method deprecation warnings ( |
|
Enable or disable method overwrite warnings |
|
Enable or disable warning for ambiguous top-level scope |
|
Limit usage of CPU features up to |
|
Set the optimization level (level is 3 if |
|
Set the lower bound on per-module optimization |
|
Set the level of debug info generation (level is 2 if |
|
Control whether inlining is permitted, including overriding |
|
Emit bounds checks always, never, or respect |
|
Disallow or enable unsafe floating point optimizations (overrides |
|
Count executions of source lines (omitting setting is equivalent to |
|
Count executions but only in files that fall under the given file path/directory. The |
|
Append coverage information to the LCOV tracefile (filename supports format tokens). |
|
Count bytes allocated by each source line (omitting setting is equivalent to "user") |
|
Count bytes but only in files that fall under the given file path/directory. The |
|
Launch a bug report session. It can be used to start a REPL, run a script, or evaluate expressions. It first tries to use BugReporting.jl installed in current environment and falls back to the latest compatible BugReporting.jl if not. For more information, see |
|
Enable or disable JIT compiler, or request exhaustive or minimal compilation |
|
Generate an object file (including system image data) |
|
Generate a system image data file (.ji) |
|
Remove docstrings and source location info from system image |
|
Remove IR (intermediate representation) of compiled functions |
|
Generate unoptimized LLVM bitcode (.bc) |
|
Generate LLVM bitcode (.bc) |
|
Generate an assembly file (.s) |
|
Generate an incremental output file (rather than complete) |
|
Print precompile statements for methods compiled during execution or save to a path |
|
Force generate code in imaging mode |
Compatibility: Julia 1.1
In Julia 1.0, the default |