# Getting a REPL after executing startup code

**URL:** <https://discourse.julialang.org/t/getting-a-repl-after-executing-startup-code/92537>\
**Category:** General Usage\
**Tags:** repl\
**Created:** [January 5, 2023, 4:21am UTC](https://discourse.julialang.org/t/getting-a-repl-after-executing-startup-code/92537 "2023-01-05T04:21:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![GHTaarn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ghtaarn/32/216007_2.png) [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)\
**Post date:** [January 5, 2023, 4:21am UTC](https://discourse.julialang.org/t/getting-a-repl-after-executing-startup-code/92537/1 "2023-01-05T04:21:11Z")

</div>

I would like to pass some initial code to Julia and then continue with a REPL, from bash (the Linux command line) I input

```bash
echo 'println(4)' | julia -i

```

which prints out “4” and exits. How do I get Julia to give me a REPL instead of just exiting?

---

<div class="post-metadata">

**Author:** ![Krastanov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krastanov/32/6817_2.png) [@Krastanov](https://discourse.julialang.org/u/Krastanov)\
**Post date:** [January 5, 2023, 4:28am UTC](https://discourse.julialang.org/t/getting-a-repl-after-executing-startup-code/92537/2 "2023-01-05T04:28:11Z")

</div>

`julia -i -e "println(4)"`

or

```julia
my_variable=`echo "println(4)"`
julia -i -e $my_variable

```

or

```julia
echo "println(4)" >> tmp_file.jl
julia -i tmp_file.jl

```

---

<div class="post-metadata">

**Author:** ![GHTaarn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ghtaarn/32/216007_2.png) [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)\
**Post date:** [January 5, 2023, 4:33am UTC](https://discourse.julialang.org/t/getting-a-repl-after-executing-startup-code/92537/3 "2023-01-05T04:33:15Z")

</div>

Seeing is my command is not always “echo”, I would have to use the second or third option, but why does my original bash command not work?

---

<div class="post-metadata">

**Author:** ![Krastanov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krastanov/32/6817_2.png) [@Krastanov](https://discourse.julialang.org/u/Krastanov)\
**Post date:** [January 5, 2023, 4:41am UTC](https://discourse.julialang.org/t/getting-a-repl-after-executing-startup-code/92537/4 "2023-01-05T04:41:46Z")

</div>

Not sure. Here is my rough guess: The pipe `|` sends the STDOUT stream of `echo "..."` to the STDIN stream of `julia`. When `echo` exits, the status of its stream is EOF (end of file). When reaching `EOF`, `julia` is supposed to exit. You can simulate the `EOF` by pressing ctrl+D (which is how I usually close interpreters like `julia` and `python`). It is probably too late to change that behavior for julia.

This seems to discuss some of the EOF and piping details: [shell - Does `echo -n | ...` send an EOF to the pipe? - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/610406/does-echo-n-send-an-eof-to-the-pipe)

---

<div class="post-metadata">

**Author:** ![GHTaarn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ghtaarn/32/216007_2.png) [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)\
**Post date:** [January 5, 2023, 4:57am UTC](https://discourse.julialang.org/t/getting-a-repl-after-executing-startup-code/92537/5 "2023-01-05T04:57:32Z")

</div>

Thank you, that sounds like a likely explanation. I could not find documentation for this on the man page, are you aware of this being documented elsewhere? Is there a good reason not to document this on the man page (i.e. would it make sense for me to submit a pull request updating the man page?)?

---

<div class="post-metadata">

**Author:** ![Krastanov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krastanov/32/6817_2.png) [@Krastanov](https://discourse.julialang.org/u/Krastanov)\
**Post date:** [January 5, 2023, 5:10am UTC](https://discourse.julialang.org/t/getting-a-repl-after-executing-startup-code/92537/6 "2023-01-05T05:10:42Z")

</div>

I am certain a PR would be appreciated. There might be some back and forth about how exactly to make the edit, but it would not hurt to try.

---

<div class="post-metadata">

**Author:** ![GHTaarn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ghtaarn/32/216007_2.png) [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)\
**Post date:** [January 5, 2023, 5:11am UTC](https://discourse.julialang.org/t/getting-a-repl-after-executing-startup-code/92537/7 "2023-01-05T05:11:38Z")

</div>

```bash
echo 'println(4)' | xargs -0 julia -ie

```

also does not give a REPL. Sorry for all the questions here, but do you feel that the explanation that you gave also can explain this?

---

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [January 5, 2023, 9:36am UTC](https://discourse.julialang.org/t/getting-a-repl-after-executing-startup-code/92537/8 "2023-01-05T09:36:20Z")

</div>

Did you really mean `xargs -0` ? Because `-o` (reconnect child’s stdin to `tty`) works

```julia
echo 'println(4)' | xargs -o julia -i --banner=no -e

```

---

<div class="post-metadata">

**Author:** ![jmair](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmair/32/35117_2.png) [@jmair](https://discourse.julialang.org/u/jmair)\
**Post date:** [January 5, 2023, 10:22am UTC](https://discourse.julialang.org/t/getting-a-repl-after-executing-startup-code/92537/9 "2023-01-05T10:22:32Z")

</div>

Would this work?

```plaintext
echo "Hello" && julia

```

Edit: This won’t do what you want, I misread.

---

<div class="post-metadata">

**Author:** ![GHTaarn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ghtaarn/32/216007_2.png) [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)\
**Post date:** [January 5, 2023, 3:35pm UTC](https://discourse.julialang.org/t/getting-a-repl-after-executing-startup-code/92537/10 "2023-01-05T15:35:51Z")

</div>

Thank you, I did actually mean -0 (did not know about -o , but it is exactly what I need). The -0 flag does however improve things so that it is possible to do:

```bash
echo 'println("Hello")' | xargs -o0 julia -i --banner=no -e

```
