# Project handling for command line scripts

**URL:** https://discourse.julialang.org/t/project-handling-for-command-line-scripts/35827
**Category:** Package Management
**Tags:** pkg
**Created:** [March 11, 2020, 7:00am UTC](https://discourse.julialang.org/t/project-handling-for-command-line-scripts/35827 "2020-03-11T07:00:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)
#### Post date: [March 11, 2020, 7:00am UTC](https://discourse.julialang.org/t/project-handling-for-command-line-scripts/35827/1 "2020-03-11T07:00:59Z")

</div>

Is there a good way to specify projects for command line Julia scripts? e.g. I have a script `foo.jl` that is intended to be called from the command line: how do I ensure that it gets the correct Project.toml file (which, for the time being, we assume resides in the same directory as the script), and ideally instantiate the Project if it hasn’t already?

The best I’ve come up with so far is to start my scripts with

```julia
#!/usr/bin/env julia
using Pkg
Base.ACTIVE_PROJECT[] = @ __DIR__ # Pkg.activate(@ __DIR__ ) creates an annoying message
Pkg.instantiate()

```

This seems like overkill (not to mention uses an internal variable). Is there a better way to do this?

---

<div class="post-metadata">

### Author: ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)
#### Post date: [March 11, 2020, 7:09am UTC](https://discourse.julialang.org/t/project-handling-for-command-line-scripts/35827/2 "2020-03-11T07:09:21Z")

</div>

Could you add the project to the shebang:

```julia
#!/usr/bin/env julia --project=...

```

?

---

<div class="post-metadata">

### Author: ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)
#### Post date: [March 11, 2020, 7:24am UTC](https://discourse.julialang.org/t/project-handling-for-command-line-scripts/35827/3 "2020-03-11T07:24:50Z")

</div>

Here is a pattern that I use sometimes:

```julia
#!/bin/bash
# -*- mode: julia -*-
#=
JULIA="${JULIA:-julia --color=yes --startup-file=no}"
export JULIA_PROJECT="$(dirname ${BASH_SOURCE[0]})"

set -ex
${JULIA} -e 'using Pkg; Pkg.instantiate()'

export JULIA_LOAD_PATH="@"
exec ${JULIA} "${BASH_SOURCE[0]}" "$@"
=#
using Whatever
...

```

Ref: [https://docs.julialang.org/en/latest/manual/faq/#How-do-I-pass-options-to-julia-using-#!/usr/bin/env?-1](https://docs.julialang.org/en/latest/manual/faq/#How-do-I-pass-options-to-julia-using-#!/usr/bin/env?-1)

Not sure if this is less overkill, though.

---

<div class="post-metadata">

### Author: ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)
#### Post date: [March 11, 2020, 12:36pm UTC](https://discourse.julialang.org/t/project-handling-for-command-line-scripts/35827/4 "2020-03-11T12:36:15Z")

</div>

the challenge is specifying the project path in the shebang
