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

**URL:** <https://discourse.julialang.org/t/how-to-call-a-julia-variable-in-memory-from-the-shell/69969>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 18, 2021, 11:57am UTC](https://discourse.julialang.org/t/how-to-call-a-julia-variable-in-memory-from-the-shell/69969 "2021-10-18T11:57:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [October 18, 2021, 11:57am UTC](https://discourse.julialang.org/t/how-to-call-a-julia-variable-in-memory-from-the-shell/69969/1 "2021-10-18T11:57:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [October 18, 2021, 12:04pm UTC](https://discourse.julialang.org/t/how-to-call-a-julia-variable-in-memory-from-the-shell/69969/2 "2021-10-18T12:04:59Z")

</div>

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

If that is what you want, do:

```julia
julia -i test.jl

```

it will run the script and keep the session open.

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [October 18, 2021, 12:09pm UTC](https://discourse.julialang.org/t/how-to-call-a-julia-variable-in-memory-from-the-shell/69969/3 "2021-10-18T12:09:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [October 18, 2021, 12:11pm UTC](https://discourse.julialang.org/t/how-to-call-a-julia-variable-in-memory-from-the-shell/69969/4 "2021-10-18T12:11:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 18, 2021, 12:29pm UTC](https://discourse.julialang.org/t/how-to-call-a-julia-variable-in-memory-from-the-shell/69969/5 "2021-10-18T12:29:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LeePhillips](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leephillips/32/205514_2.png) [@LeePhillips](https://discourse.julialang.org/u/LeePhillips)\
**Post date:** [October 18, 2021, 1:00pm UTC](https://discourse.julialang.org/t/how-to-call-a-julia-variable-in-memory-from-the-shell/69969/6 "2021-10-18T13:00:56Z")

</div>

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](https://juliaio.github.io/HDF5.jl/stable/).
