# Setting fish shell environment variables correctly for julia shell

**URL:** <https://discourse.julialang.org/t/setting-fish-shell-environment-variables-correctly-for-julia-shell/90158>\
**Category:** General Usage\
**Tags:** shell\
**Created:** [November 12, 2022, 11:16am UTC](https://discourse.julialang.org/t/setting-fish-shell-environment-variables-correctly-for-julia-shell/90158 "2022-11-12T11:16:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)\
**Post date:** [November 12, 2022, 11:16am UTC](https://discourse.julialang.org/t/setting-fish-shell-environment-variables-correctly-for-julia-shell/90158/1 "2022-11-12T11:16:53Z")

</div>

I need to come back to an [old question](https://discourse.julialang.org/t/run-cmd-does-not-use-my-shell/9833). I am unable to see my system ENV variables in the julia shell.

I set the env vars in fish with `set -U key value` like so:

```julia
floswald@PTL11077 ~> set -U JULIA_VAR howdie
floswald@PTL11077 ~> head ~/.config/fish/fish_variables
# This file contains fish universal variable definitions.
# VERSION: 3.0
SETUVAR JULIA_VAR:howdie

```

and I can get this variable in any new login shell on my machine:

```julia
Last login: Sat Nov 12 12:01:20 on ttys003
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
floswald@PTL11077 ~> echo $JULIA_VAR 
howdie

```

notice that this fish shell is my default login shell:

```julia
floswald@PTL11077 ~> echo $SHELL
/opt/homebrew/bin/fish

```

however, I cannot see the variable in the shell that is called by julia:

```julia
floswald@PTL11077 /etc [1]> julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.8.0 (2022-08-17)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

shell> echo $SHELL
ERROR: UndefVarError: SHELL not defined
Stacktrace:
 [1] top-level scope
   @ none:1

shell> echo $JULIA_VAR
ERROR: UndefVarError: JULIA_VAR not defined
Stacktrace:
 [1] top-level scope
   @ none:1

shell> 

```

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [November 12, 2022, 4:32pm UTC](https://discourse.julialang.org/t/setting-fish-shell-environment-variables-correctly-for-julia-shell/90158/2 "2022-11-12T16:32:10Z")

</div>

> [@floswald](#):
>
> `echo $SHELL`

This is trying to interpolate a _Julia variable_ `SHELL` into the command:

```julia
julia> SHELL = "hello, world";

shell> echo $SHELL
hello, world

```

Compare with

```julia
shell> echo $(ENV["SHELL"])
/bin/bash

shell> bash -c 'echo $SHELL'
/bin/bash

```

---

<div class="post-metadata">

**Author:** ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)\
**Post date:** [November 12, 2022, 5:01pm UTC](https://discourse.julialang.org/t/setting-fish-shell-environment-variables-correctly-for-julia-shell/90158/3 "2022-11-12T17:01:39Z")

</div>

good point! - that’s obviously wrong. notice however that this was not the solution - the ENV var was still invisible. fully due to my ignorance about my own shell. anyway, hopefully some other fish users could use this. **The key is to `set` the fish variable not only as Universal but also as exported** :

```julia
floswald@PTL11077 > set -U JULIA_VAR howdie
floswald@PTL11077 > julia -q -e 'using Test; @test haskey(ENV,"JULIA_VAR")'
Test Failed at none:1
  Expression: haskey(ENV, "JULIA_VAR")
ERROR: There was an error during testing

now set the env variable with the export (x) flag:

floswald@PTL11077 > set -Ux JULIA_VAR howdie
floswald@PTL11077 > julia -q -e 'using Test; @test haskey(ENV,"JULIA_VAR")'
floswald@PTL11077 >
```
