# Setup an environment from a shell script

**URL:** <https://discourse.julialang.org/t/setup-an-environment-from-a-shell-script/27012>\
**Category:** New to Julia\
**Tags:** shell, pkg\
**Created:** [July 31, 2019, 2:11am UTC](https://discourse.julialang.org/t/setup-an-environment-from-a-shell-script/27012 "2019-07-31T02:11:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacob-roth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacob-roth/32/1862_2.png) [@jacob-roth](https://discourse.julialang.org/u/jacob-roth)\
**Post date:** [July 31, 2019, 2:11am UTC](https://discourse.julialang.org/t/setup-an-environment-from-a-shell-script/27012/1 "2019-07-31T02:11:55Z")

</div>

I’m hoping to run some simulations from a shell script. The structure is something like:

```julia
parent
  \__ Manifest.toml
  \__ Project.toml
  \__dir
    \__ sim.sh
    \__ env.jl
    \__ simulate.jl

```

where `sim.sh` contains

```julia
#!/bin/sh
julia simulate.jl

```

`simulate.jl` contains

```julia
include("env.jl")
println("...now running simulations...")

```

and `env.jl` contains

```julia
using Pkg
Pkg.activate("../.")
Pkg.instantiate()

```

to pull from Manifest/Project files I have in `parent/`. However, when I run `$ ./sim.sh`, I get the following error:

```julia
ERROR: LoadError: ArgumentError: Module Pkg not found in current path.
Run `Pkg.add("Pkg")` to install the Pkg package.
Stacktrace:
 [1] _require(::Symbol) at ./loading.jl:428
 [2] require(::Symbol) at ./loading.jl:398
 [3] include_from_node1(::String) at ./loading.jl:569
 [4] include(::String) at ./sysimg.jl:14
 [5] process_options(::Base.JLOptions) at ./client.jl:305
 [6] _start() at ./client.jl:371

```

Am I doing something wrong??

* * *

Here’s my version info:

```julia
Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
  JULIA_LOAD_PATH = ...

```

---

<div class="post-metadata">

**Author:** ![jacob-roth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacob-roth/32/1862_2.png) [@jacob-roth](https://discourse.julialang.org/u/jacob-roth)\
**Post date:** [July 31, 2019, 2:47am UTC](https://discourse.julialang.org/t/setup-an-environment-from-a-shell-script/27012/2 "2019-07-31T02:47:49Z")

</div>

Ah, I just need to call julia from `$JULIA_BINDIR/julia` in the shell script and make sure the shebang references the current environment `#!/usr/bin/env sh`

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [July 31, 2019, 3:40am UTC](https://discourse.julialang.org/t/setup-an-environment-from-a-shell-script/27012/3 "2019-07-31T03:40:22Z")

</div>

@jacob\_roth It is very worthwhile documenting this. You are running the simulation in a batch system such as Slurm or PBS? There are differences between interactive and non-interactive login shells.  
I think you have come across a situation where the non-interactive shell is different.

I don’t need to see the output, which might contain proprietary information. Howwer could you submit a script which simply runs the env command and similary run env at the terminal, then do a diff of the results?

Of course, I may be wrong here.

---

<div class="post-metadata">

**Author:** ![jacob-roth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacob-roth/32/1862_2.png) [@jacob-roth](https://discourse.julialang.org/u/jacob-roth)\
**Post date:** [July 31, 2019, 6:43am UTC](https://discourse.julialang.org/t/setup-an-environment-from-a-shell-script/27012/4 "2019-07-31T06:43:13Z")

</div>

@johnh: I think I was just using the “wrong” version of Julia. My default path wasn’t properly set up 🙂
