0

Using arch-linux with xorg and dwm, environment variables seem not available to the wohle system. E.g. when starting the NNN file-browser inside a manually started terminal emulator (st) all bookmarks are available (NNN loads settings through environment variables, here set inside the .profile file, which loads them from the .bashrc file). However, when I start NNN by a dwm-keybinding the bookmarks are not(!) available (here NNN is started via st -e nnn more precisely i.e. via { "st", "-e", "nnn", NULL }; inside the config.h file of dwm). So it seems that here the environment variables are not loaded in this case.

Do you have any idea why? Or how to solve this issue?

EDIT added the .profile file content:

if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

EDIT-2: Added the bookmarks loading line inside .bashrc

export NNN_BMS='h:~/;d:~/Documents/'
alex
  • 983
  • Again, where are you defining env variables? If you're using .bashrc they will not be read. – terdon Nov 12 '20 at 15:14
  • @terdon: Thank you again. So I redirect inside the .profile to also read .bashrc (with: . "$HOME/.bashrc") so it certainly reads the variables when starting. It seems more discrete -- however too deep for me. – alex Nov 19 '20 at 19:49
  • Please [edit] your question, explain exactly how you are defining the variables (show us the lines in .profile that read .bashrc) and also make sure that your .bashrc is being read (there is usually a line that causes it to exit if it is not being read by an interactive shell, see Why does bashrc check whether the current shell is interactive?). Then, we also need to know how you're starting your X server since some login managers do read .profile while others don't. The likeliest culprit is that bashrc is not being read since your st isn't being ru – terdon Nov 19 '20 at 19:58
  • @terdon done and thanks – alex Nov 19 '20 at 20:19
  • Thanks, but that just shows that you read .bashrc. You don't show if your bashrc has a line like the one mentioned in the post I linked to and you don't explain how you start your graphical session. The main issue is almost certainly that .bashrc is exiting immediately, please read the linked post. Also, please avoid posting images of text. Instead, copy/paste the text into your question and use the formatting tools to format it as code. – terdon Nov 19 '20 at 20:22
  • @terdon: Thank you. I added the required lines. And I've also tried to understand the linked post. However, the post is probably a little to complicated for my experience. I might not really grasp the core difference between the shell and bash, as well as what/why a 'interactive' shell actually is/exists. – alex Nov 19 '20 at 22:17
  • Can you just try adding the variables to .profile instead of .bashrc? That's the simplest way of checking. It's also the right place for global variables, they have no business being set in .bashrc. – terdon Nov 20 '20 at 09:22

1 Answers1

0

.profile is read by Bourne based shells (e.g. /bin/sh and bash). If no such shell is started then .profile won't be read. It sounds like you are launching st from dwm and nnn from st with no shell.

If an environment variable is set in the parent process (dwm in this case, and any antecedents) and it will be inherited by all spawned children. Depending on how you start X there are many ways to do this - too many to enumerate without more context but maybe in ~/.xinitrc or ~/.xsession.

An alternative approach is to use PAM which, by default on arch I think, reads $HOME/.pam_environment when you login and you can put NAME=VALUE pairs in there.

  • Thank you for the answer. Can you please tell me what you need to know precisely. I start the NNN inside a terminal with a keybinding st -e nnn set inside the dwm configuration. And it starts properly -- inside the st terminal emulator --, however without reading the .profile. I use .xinitrc for launching the window manager. – alex Nov 19 '20 at 22:22
  • Then you should be able to set the environment variable in .xinitrc. Edit it with a text editor and before the line running dwm just add something like:

    NNN_BMS='h:~/;d:~/Documents/' export NNN_BMS

    – user133831 Nov 20 '20 at 10:24