Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

terminal

julia

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.

like image 771
Alec Avatar asked Dec 15 '19 19:12

Alec


2 Answers

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
like image 55
aramirezreyes Avatar answered Oct 16 '22 18:10

aramirezreyes


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
like image 37
张实唯 Avatar answered Oct 16 '22 20:10

张实唯