Search code examples
linuxjulia

Cannot run julia file - syntax error close to the unexpected token


I wrote a simple "hello world" in julia, but I cannot figure out on how to run the code. I've tried to run by ./nameOfMyFile.jl and the terminal returned to me that I have syntax errors.

My code is just:

println("hello world")

Which works perfectly if I run julia on the terminal and write the code after that...

The error is something like( I am translating it from Portuguese):

./hello_world.jl: line 1:syntax error close to the unexpected token "hello world" ./hello_world.jl: line 1: println("hello world")'

I'm using vim, Debian 8 and julia 0.3.2


Solution

  • Two ways I can think of to achieve what you want

    Open a terminal and do either one of the following

    Inside the julia relp, that is, if you run julia in the terminal by running

    julia
    

    and when you're in, do

    include("nameoffile.jl")
    

    if you simple want to run the file, in the terminal do

    julia nameoffile.jl