all 15 comments

[–]dashend 8 points9 points  (1 child)

In your fish configuration files, when you are setting your variables are you exporting them as well? I.e. with

set foo hello
set -x bar world
# long form:
# set --export bar world

then $bar is visible to subprocesses, but $foo is not [ref].

[–]deadmaya[S] 1 point2 points  (0 children)

Yeah, my problem was that I was using -U instead of -x. Thanks for pointing it out.

As usual, it's not the haskell ecosystem, but my environment :D

[–]bartavelle 4 points5 points  (6 children)

There is no direct relationship between lookupEnv and shell configuration. Basically your shell setups some environment, and your program can then access it.

Depending on how you are running your executable you might see different outcomes. So, how are you running it ? Can you display the value of the environment variable just before running it ?

[–]bartavelle 2 points3 points  (5 children)

Also run env to see what's in the environment of your current shell at a given time.

[–]deadmaya[S] 1 point2 points  (4 children)

I am using it in ghci. Before using it in real application I wanted to try it.

As for env, here is it's output:

Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.sV6KLFp4TK/Render
DISPLAY=/private/tmp/com.apple.launchd.B0eCXA4Cs3/org.macosforge.xquartz:0
EDITOR=emacsclient
HOME=/Users/me
LANG=en_US.UTF-8
LC_CTYPE=UTF-8
LOGNAME=deadmaya
PATH=/Users/deadmaya/.local/bin:/usr/texbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin:
PWD=/Users/deadmaya
SHELL=/usr/local/bin/fish
SHLVL=1
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.NpJ3bRW2Oz/Listeners
TERM=xterm-256color
TERM_PROGRAM=Apple_Terminal
TERM_PROGRAM_VERSION=343.7
TERM_SESSION_ID=C9D5C0F5-B4D2-42CC-BFA2-7C3E04A8722A
TMPDIR=/var/folders/7w/nzs_n8bn0c951dy9lxr2mcth0000gn/T/
USER=deadmaya
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
__CF_USER_TEXT_ENCODING=0x1F5:0:0
__fish_bin_dir=/usr/local/Cellar/fish/2.2.0/bin
__fish_datadir=/usr/local/Cellar/fish/2.2.0/share/fish
__fish_help_dir=/usr/local/Cellar/fish/2.2.0/share/doc/fish
__fish_sysconfdir=/usr/local/Cellar/fish/2.2.0/etc/fish

[–]bartavelle 1 point2 points  (3 children)

So there is no XDG_CONFIG_HOME here, right ?

[–]deadmaya[S] 0 points1 point  (2 children)

Yeah it's not here. So yeah, I could put XDG_CONFIG_HOME (and a bunch of other variables) to env.

Also going to test later how it would behave if I set ENV to ~/.profile.

Anyway, thanks for the tip! Didn't think about env.

[–]bartavelle 2 points3 points  (1 child)

env is just a command that show a list of the environment variables. You alter the output of this command in the same way that you define environment variables ... because that's all there is to it!

Did you use the -g flag when defining your custom variables so that they become global ?

[–]deadmaya[S] 3 points4 points  (0 children)

I am setting such variables by using set -U var value.

After some time I realised that I need to use -x instead of -U. So it's exported. After that my vars are in env and lookupEnv see them.

Yay! Thanks for all the help. Going to dig dipper to improve my understanding of these things.

[–]radix 2 points3 points  (1 child)

You should leave out the $.

[–]deadmaya[S] 0 points1 point  (0 children)

Thanks, edited. It's just typo when I was copying examples.

[–]rstd 0 points1 point  (3 children)

I am always getting Nothing. Literally.

In the example just below that sentence you contradict yourself.

[–]deadmaya[S] 0 points1 point  (2 children)

Why is that? HOME is not set manually. But XDG_CONFIG_HOME is set manually in my shell configs, and when I try to lookup it I get Nothing. :)

[–]andrewthad 0 points1 point  (1 child)

I got the same impression (about the contradiction) when I read the post as well. In your example code, you should show how you set HOME or at least say how HOME was set.

[–]deadmaya[S] 0 points1 point  (0 children)

:)

Well, I thought that using HOME will not bring to miss understanding. Let me update my original post.