Julia Interactive Commands
Julia REPL (Read-Eval-Print Loop) is Julia's interactive command-line environment, an excellent tool for learning and experimenting with Julia code.
Starting REPL
Enter julia in terminal to start REPL:
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.10.0 (2023-12-25)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia>Basic Usage
Executing Expressions
Enter expressions directly and press Enter:
julia> 1 + 2
3
julia> "Hello, " * "Julia!"
"Hello, Julia!"
julia> sqrt(16)
4.0Variable Assignment
julia> x = 10
10
julia> y = 20
20
julia> x + y
30Multi-line Input
Use semicolon ; to suppress output:
julia> a = 1;
julia> b = 2;
julia> a + b
3For multi-line code, enter directly:
julia> function greet(name)
println("Hello, $name!")
end
greet (generic function with 1 method)
julia> greet("Julia")
Hello, Julia!REPL Modes
Julia REPL has four main modes, switched using special keys.
1. Julian Mode (Default)
Prompt: julia>
Used for executing Julia code.
2. Help Mode
Press ? to enter, prompt changes to: help?>
help?> println
search: println printstyled print sprint isprint
println([io::IO], xs...)
Print (using print) xs to io followed by a newline.
If io is not supplied, prints to the default output stream stdout.Press Backspace to return to Julian mode.
3. Package Mode
Press ] to enter, prompt changes to: (@v1.10) pkg>
(@v1.10) pkg> status
Status `~/.julia/environments/v1.10/Project.toml`
[336ed68f] CSV v0.10.12
[a93c6f00] DataFrames v1.6.1Common commands:
pkg> add PackageName # Install package
pkg> rm PackageName # Remove package
pkg> update # Update all packages
pkg> status # View installed packages
pkg> instantiate # Install dependencies from Project.tomlPress Backspace to return to Julian mode.
4. Shell Mode
Press ; to enter, prompt changes to: shell>
shell> pwd
/home/user
shell> ls
Documents Downloads julia-projectPress Backspace to return to Julian mode.
Keyboard Shortcuts
Editing Shortcuts
| Shortcut | Function |
|---|---|
Ctrl + C | Interrupt current execution |
Ctrl + D | Exit REPL (on empty line) |
Ctrl + L | Clear screen |
Ctrl + R | Search command history |
↑ / ↓ | Browse command history |
Tab | Auto-complete |
Line Editing Shortcuts
| Shortcut | Function |
|---|---|
Ctrl + A | Move to line start |
Ctrl + E | Move to line end |
Ctrl + K | Delete to line end |
Ctrl + U | Delete to line start |
Ctrl + W | Delete previous word |
Auto-Completion
Press Tab for auto-completion:
Function Name Completion
julia> prin<Tab>
print println printstyledModule Member Completion
julia> using LinearAlgebra
julia> LinearAlgebra.<Tab>
BLAS Diagonal Factorization ...Unicode Completion
Julia supports Unicode characters via LaTeX-style input:
julia> \alpha<Tab>
α
julia> \sqrt<Tab>
√
julia> \pi<Tab>
πCommon Unicode symbols:
| Input | Result | Meaning |
|---|---|---|
\alpha | α | Greek letter |
\beta | β | Greek letter |
\pi | π | Pi |
\sqrt | √ | Square root |
\sum | ∑ | Sum |
\in | ∈ | Element of |
\notin | ∉ | Not element of |
\leq | ≤ | Less or equal |
\geq | ≥ | Greater or equal |
\neq | ≠ | Not equal |
History
View History
Use up/down arrow keys to browse previous commands.
Search History
Press Ctrl + R to enter reverse search mode:
(reverse-i-search)`pri': println("Hello")History File
History is saved in ~/.julia/logs/repl_history.jl.
Special Variables
ans
ans stores the result of the last expression:
julia> 1 + 2
3
julia> ans * 2
6Running Scripts
Run Script in REPL
julia> include("myscript.jl")Command Line Script
julia myscript.jlWith Arguments
julia myscript.jl arg1 arg2Access arguments in script:
# myscript.jl
for arg in ARGS
println(arg)
endStartup Options
Common Command Line Options
# Specify thread count
julia -t 4
# Execute expression
julia -e 'println("Hello")'
# Quiet mode (no banner)
julia -q
# Enter REPL after running script
julia -i script.jl
# Optimization level
julia -O3 script.jl
# View help
julia --helpStartup File
Julia automatically executes ~/.julia/config/startup.jl on startup:
# ~/.julia/config/startup.jl
println("Welcome to Julia!")
# Customize REPL behavior
atreplinit() do repl
# Custom REPL initialization
endPractical Tips
1. Quick Function Testing
julia> f(x) = x^2 + 2x + 1
f (generic function with 1 method)
julia> f(3)
16
julia> f.(1:5) # Vectorized call
5-element Vector{Int64}:
4
9
16
25
362. View Types
julia> typeof(1)
Int64
julia> typeof(1.0)
Float64
julia> typeof("hello")
String3. View Methods
julia> methods(+)
# [Shows all methods of + operator]4. Timing
julia> @time sum(1:1000000)
0.000001 seconds
5000005000005. Memory Allocation
julia> @allocated rand(1000)
8000Exiting REPL
Multiple ways to exit:
julia> exit()
# Or press Ctrl + D (on empty line)Next Steps
After mastering REPL usage, continue learning:
- Basic Syntax - Julia fundamentals
- Data Types - Understanding Julia's type system