How to call a Julia variable in memory from the shell?

For example, if I have a Julia program test.jl, and I run it in a shell as below:
julia test.jl

When done, I did not save the variables in the hard disk, but all the variables should be in the memory, am I right? How do I call these variables from the shell later on?

Thanks.

Do you want to continue working on the loaded file, within Julia?

If that is what you want, do:

julia -i test.jl

it will run the script and keep the session open.

2 Likes

Thanks for the trick!

So if I just run julia test.jl, there would be no way to access the Julia variables from the shell? It would take a long time for my program to run again.

No. When Julia finished running test.jl, the process ended and all memory was returned to the operating system for recycling.

1 Like

to access something from shell, you probably need to print it to stdout. After all, shell is not meant to be a programming language for your real work

1 Like

I believe you want to run a program and use its results later, specifically from a shell (REPL) session. To do this you need to save the results somewhere. The simplest way is to modify your program so that it writes the results to a text file; then you can read the file in the REPL or in another program. Another, in some ways better, solution is to use something like the HDF5 file format, that can store structured data and even graphics in a way that will not lose precision. Julia has a package that makes it convenient to work with this file format: Home · HDF5.jl.

1 Like