I would like to pass some initial code to Julia and then continue with a REPL, from bash (the Linux command line) I input
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?
I would like to pass some initial code to Julia and then continue with a REPL, from bash (the Linux command line) I input
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?
julia -i -e "println(4)"
or
my_variable=`echo "println(4)"`
julia -i -e $my_variable
or
echo "println(4)" >> tmp_file.jl
julia -i tmp_file.jl
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?
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
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?)?
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.
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?
Did you really mean xargs -0 ? Because -o (reconnect child’s stdin to tty) works
echo 'println(4)' | xargs -o julia -i --banner=no -e
Would this work?
echo "Hello" && julia
Edit: This won’t do what you want, I misread.
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:
echo 'println("Hello")' | xargs -o0 julia -i --banner=no -e