Renato Melo
Renato Melo

Reputation: 184

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

Well, 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")

Wich 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

Upvotes: 2

Views: 479

Answers (3)

Alexander Morley
Alexander Morley

Reputation: 4181

If you want to execute it directly from the terminal you can add a shebang to the beggining of your script i.e.

#!/usr/bin/env julia println("hello world")

and then make it executable using chmod

[user@computer]$ chmod +x hello

then it should run as expected :)

./hello

will print "hello world" to your terminal :)

Upvotes: 3

Michael Ohlrogge
Michael Ohlrogge

Reputation: 10980

Based on discussions on GitHub like this one it sounds like this issue is more due to the shell than to Julia. Nevertheless, I would strongly recommend upgrading to the latest version of Julia, 0.4.6. The version that you are using is quite old and lacks a lot of improvements, including ones addressing issues at least similar to what you are experiencing.

Upvotes: 0

isebarn
isebarn

Reputation: 3940

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

Upvotes: 1

Related Questions