How to run julia script as a command in the terminal?

I want to create some CLI applications in julia, but instead of the users writing (in the terminal):

julia --project /path-to/src/MyScript.jl arg1 --opt-1

I want to be able to type:

myscript arg1 --opt-1
1 Like

On UNIX-like OSes, create a shell script called myscript that passes its arguments to the Julia command, then make that script executable. On Windows, no idea how to do that, sorry.

4 Likes

Well, on Windows you can write a .bat file…

2 Likes

Take a look at this one in the FAQs https://docs.julialang.org/en/v1/manual/faq/#How-do-I-pass-options-to-julia-using-#!/usr/bin/env?

1 Like

You also may be interested in ArgParse.jl.

2 Likes

I tested here, and we can actually create a .bat file that calls julia passing the correct arguments, and run it in the terminal like a normal command, assuming that the script is on a folder which is on PATH. Also, we can actually use the unix approach in Windows if the user uses git-bash (I use git-bash with zsh). Thanks everyone!

1 Like