Alec
Alec

Reputation: 4482

How to evaluate a Julia expression from the terminal (not the REPL)?

Is there a way to run a (set of) Julia commands without entering the REPL?

E.g. julia.exe "using IJulia; notebook()" doesn't work.

MY end goal is to be able to create a clickable batch file that allows me and others I share it with to open Jupyter without needing to worry about the command line or REPL.

Upvotes: 7

Views: 267

Answers (2)

张实唯
张实唯

Reputation: 2862

In addition with -e option, julia also read and evaluate stdin. Thus you can also do these using shell pipes/redirections:

$ echo '1+1' | julia
2

$ julia <<EOF
> 1+1
> EOF
2

$ julia <<< 1+1
2

Upvotes: 1

aramirezreyes
aramirezreyes

Reputation: 1365

You can use the -e flag to the julia executable like this:

julia.exe -e "using IJulia; notebook()"

If you don't want the session to die after running, and you want it to give you a REPL afterwards, you can pass -i as:

julia.exe -e "using IJulia; notebook()" -i

This option and others is documented in the "Getting started" section of the documentation

Or by running the executable with the -h flag:

julia.exe -h

Upvotes: 5

Related Questions