User environment variable - location of file

Docker does not support /etc/environment. it only looks for env vars in the user environment. (I tried).

When I want to set the default path to my compose file using the docker supported COMPOSE_FILE env variable, I need to use the EXPORT command as current user (without sudo). This works.

I would like to know where the file is located, with vars stored via the EXPORT command?
I looked in several locations mentioned in the Arch Wiki, none of them exist. Even checked locations for systemd.

Are you referring to .profile in your home directory?

Such a folder does not exist.
Let me add another var:

export COMPOSE_FIL33E="/home/asterix/docker/docker-compose.yml"   

Now I can see it has been added:

~ printenv                                                                                                                                      ✔ 
SYSTEMD_EXEC_PID=4994
SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
SESSION_MANAGER=local/obelix:@/tmp/.ICE-unix/4959,unix/obelix:/tmp/.ICE-unix/4959
GNOME_TERMINAL_SCREEN=/org/gnome/Terminal/screen/a21e65e0_0a76_4c37_8a29_dcf1e6c60253
LANG=en_GB.UTF-8
XDG_CURRENT_DESKTOP=GNOME
COLORTERM=truecolor
WAYLAND_DISPLAY=wayland-0
LC_IDENTIFICATION=nl_NL.UTF-8
LC_NAME=nl_NL.UTF-8
XDG_SESSION_CLASS=user
PWD=/home/asterix
QT_IM_MODULE=ibus
LC_MEASUREMENT=nl_NL.UTF-8
DESKTOP_SESSION=gnome
LOGUSER=asterix
XDG_MENU_PREFIX=gnome-
OLDPWD=/home/asterix
USER=asterix
DOTNET_BUNDLE_EXTRACT_BASE_DIR=/home/asterix/.cache/dotnet_bundle_extract
MOZ_ENABLE_WAYLAND=1
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
LC_NUMERIC=nl_NL.UTF-8
XDG_DATA_DIRS=/home/asterix/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop
VTE_VERSION=7200
XDG_SESSION_DESKTOP=gnome
HOME=/home/asterix
GNOME_SETUP_DISPLAY=:1
LC_TIME=nl_NL.UTF-8
MAIL=/var/spool/mail/asterix
DEBUGINFOD_URLS=https://debuginfod.archlinux.org 
GNOME_TERMINAL_SERVICE=:1.199
LC_PAPER=nl_NL.UTF-8
LOGUSERS=cheese
XDG_RUNTIME_DIR=/run/user/1000
XMODIFIERS=@im=ibus
QT_AUTO_SCREEN_SCALE_FACTOR=1
SHELL=/bin/zsh
DOTNET_ROOT=/usr/share/dotnet
LC_MONETARY=nl_NL.UTF-8
LOGNAME=asterix
LC_TELEPHONE=nl_NL.UTF-8
EDITOR=/usr/bin/nano
XDG_SESSION_TYPE=wayland
USERNAME=asterix
QT_QPA_PLATFORMTHEME=qt5ct
MOTD_SHOWN=pam
GDM_LANG=en_GB.UTF-8
PATH=/home/asterix/.local/bin:/usr/local/bin:/usr/bin:/var/lib/snapd/snap/bin:/usr/local/sbin:/home/asterix/.dotnet/tools:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
DISPLAY=:0
TERM=xterm-256color
LC_ADDRESS=nl_NL.UTF-8
XAUTHORITY=/run/user/1000/.mutter-Xwaylandauth.IX8R31
GDMSESSION=gnome
SHLVL=1
LESS_TERMCAP_mb=
LESS_TERMCAP_md=
LESS_TERMCAP_me=
LESS_TERMCAP_se=
LESS_TERMCAP_so=
LESS_TERMCAP_ue=
LESS_TERMCAP_us=
LESS=-R
PKGFILE_PROMPT_INSTALL_MISSING=1
LS_OPTIONS=--color=auto
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=00:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.avif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:*~=00;90:*#=00;90:*.bak=00;90:*.old=00;90:*.orig=00;90:*.part=00;90:*.rej=00;90:*.swp=00;90:*.tmp=00;90:*.dpkg-dist=00;90:*.dpkg-old=00;90:*.ucf-dist=00;90:*.ucf-new=00;90:*.ucf-old=00;90:*.rpmnew=00;90:*.rpmorig=00;90:*.rpmsave=00;90:
P9K_SSH=0
_P9K_SSH_TTY=/dev/pts/2
P9K_TTY=old
_P9K_TTY=/dev/pts/2
COMPOSE_FILE=/home/asterix/docker/docker-compose.yml
COMPOSE_FIL33E=/home/asterix/docker/docker-compose.yml
_=/usr/bin/printenv

I am asking in which file COMPOSE_FILE and COMPOSE_FIL33E have been added?

It’s in-memory. There is no file.

It will be either ~/.bash_profile (if you use bash) or ~/.zprofile (if you use zsh). Both files should exist in every recent-enough installation, but if they don’t, then it’s easy to create them.

My bash_profile file exists but doesn’t list the mentioned variables, it just contains:

#
# ~/.bash_profile
#

[[ -f ~/.bashrc ]] && . ~/.bashrc

The .bashrc file also exist but contains code, no variables. :man_shrugging:
It’s a bit mysterious…
I see similar questions on the forum and lots of references to Arch Wiki, but that does not seem to apply.

My system (Intel based):

 uname -r    
6.1.25-1-MANJARO
cat /etc/lsb-release 
DISTRIB_ID=ManjaroLinux
DISTRIB_RELEASE=22.1.0
DISTRIB_CODENAME=Talos
DISTRIB_DESCRIPTION="Manjaro Linux"

So, add the export command there. ~/.bash_profile is normally where environment variables are set. :wink:

Sorry I don’t understand.
When I do printenv, I see my exported variables. So they are already stored somewhere?

Should I literally add “export” at the bottom of the ~/.bash_profile file? And then run the command again to add those envs? Will I not end up with double variables?

EDIT: OK now it makes sense: closing the terminal and reopening: my docker-compose command can no longer find its config. The export command only exists during the life of the shell I am in.

In conclusion, I should simply add my env variables to the ~/.bash_profile file, not via the export command.

In memory, yes. What sets them is another matter. There are various files under /etc/profile.d that set environment variables.

Yes. Either one of the two approaches below will do. :arrow_down:

VARIABLE=value
export VARIABLE

… or… :arrow_down:

export VARIABLE=value

For exporting a bash shell function, you need to use the -f command option… :arrow_down:

export -f name-of-function-here

If you want it to become active in your current login session, then yes. ~/.bash_profile is only read upon logging in.

There is no such thing, because variable names are unique. At most you can replace a variable’s value by reassigning it.

export will — as its name says — set a variable (and its value) and export it to all subshells started from the same shell. So if you set a variable without exporting it, then it’ll only apply to the current shell, and not to a subshell, but if you export the variable, then every subshell from the current environment will inherit the variable and its value.

However, in order to make a variable permanent — with or without that it’s being exported — you need to define it in one of the files that are being sourced into your environment. Traditionally in UNIX, this would be the file ~/.profile, but the bash that ships with Arch doesn’t by default read ~/.profile. Instead, it uses ~/.bash_profile.

1 Like

Thanks, I have added export VARIABLE=value to both $HOME/.bash_profile and /etc/zsh/zshenv, since zsh is default for Manjaro Gnome.

Only in the GUI terminal sessions. The underlying system shell and the shell you use in tty sessions is bash. :wink:

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.