Is there an Official Shebang for Julia

Is there an Official Shebang for Julia and if so how do I install and use it ?

1 Like

I’m a little confused about what you mean by “install and use it”, but #!/usr/bin/env julia should work in most cases (assuming you can run it successfully on the command line).

6 Likes

In addition to the previous answer and in case you need to (portably) provide julia with additional command-line arguments, the recommended way is documented in the FAQ:

#!/bin/bash
#=
exec julia --color=yes --startup-file=no "${BASH_SOURCE[0]}" "$@"
=#

@show ARGS  # put any Julia code here
11 Likes

For the benefit of future readers of this thread, the FAQ has now changed and recommends

#!/usr/bin/env -S julia -t 4 -- project

as the header for executable Julia scripts (where you may change the Julia command line options to suit your needs).

None of the above headers work if julia is an alias, so I made the following to handle this situation as well:

#!/usr/bin/bash -i
#=
    exec bash -ic 'julia -t 4 --project "$@"' Julia "${BASH_SOURCE[0]}" "$@"
=#

println.(ARGS, '.')

Again, -t 4 --project is just an example of some Julia command line options that one could use and println.(ARGS, '.') is just an example of some Julia code.

This header is much more complex than the one from the FAQ, but as far as I can see it is more general. Please let me know if you find any issues with it, I have only tested it on myself.

1 Like