Is it possible to pipe into `julia` command without it exiting immediately after

hi there, I am wondering whether there is a flag which prevents julia from closing
like

echo 'println("my initial command which I would like to show up")' | julia

should ideally result in something like

julia> println("my initial command which I would like to show up")
my initial command which I would like to show up
julia> 

If you redirect stdin (that’s what the pipe does), then there isn’t much point in starting up the REPL, as it would also read from stdin, which is closed by this point.

However, you can run a script and then keep julia running, as follows:

$ julia --banner=no -ie 'println("my initial command which I would like to show up")'
my initial command which I would like to show up
julia> 

Note the -i switch, which forces Julia REPL into interactive mode.

HTH.

4 Likes

Thank you very much. That is almost like I wished for - the julia command is not shown inside the REPL. But this should work indeed. Thank you so much!

1 Like

True, you have to work a bit harder for a local echo effect. E.g.,

$ julia --banner=no -ie 'macro echo(cmd) :(println("julia> ", $(QuoteNode(cmd))); $cmd; println()) end' -e '@echo println("my initial command which I would like to show up")'
julia> println("my initial command which I would like to show up")
my initial command which I would like to show up

julia> 
2 Likes