The short answer is, first that your script should look like this:
function nothing()
println("nothing")
end
function print_out()
println(ARGS[1])
end
And you can call it with a argument like this:
julia -e "include(\"./hello.jl\"); print_out()" -- "hello world"
The long answer is that this is, of course, excendendly complicated, because it is not the way you should be developing in Julia.
In Julia, do the following:
- Create your script, for example, like this:
function print_out(x)
println(x)
end
- Open a Julia REPL and do:
julia> include("./hello.jl")
print_out (generic function with 1 method)
julia> print_out("hello world")
hello world
Now, better, install Revise
, and do:
julia> using Revise
julia> includet("./hello.jl") # note the "t" in includet
julia> print_out("hello world")
hello world
The cool thing now is that if you modify the script and save it, and just run the function print_out
again without leaving the REPL, the modification of the function will be taken into account.
I have some personal notes on this here and here. Of course you will find much more information in other sources, like here and in the docs of the Revise package, for example.
Edit: One alternative to the “first answer” is to call the function from within the script, for example:
function print_out()
println(ARGS[1])
end
print_out()
and then do
% julia hello.jl -- "hello world"
hello world
But this is not the most common approach for development, or use of Julia, which is the “Revise” approach mentioned, with a persistent REPL.