1

I have a script called display, which sets my desktop background using feh. It does so with the following line:

feh --bg-scale $WALLPAPER &

The environment variable $WALLPAPER is initialized in my .bashrc. The script works correctly if I execute it from an ordinary shell after login.

I want the script to be executed by i3 on startup. Therefore, I added the following line to ~/.config/i3/config:

exec display

and it doesn't work. I tried to redirect STDERR to a file, and the result is:

feh: No loadable images specified.
See 'man feh' for detailed usage information

Moreover, if I try to echo $WALLPAPER inside display, I get a blank line. So the environment variable is not initialized yet. Fine - I tried to add exec /bin/bash -c "source ~/.bashrc" on the line above, but that seems to make no difference. How can I make sure this variable is initialized when i3 starts up?

2 Answers 2

0

Is i3 being executed by a different user, try providing an absolute path to the source command instead of relative path with ~

1
  • Running ps -al | grep i3 returns 0 S 1000 4609 4591 0 80 0 - 38323 ep_pol tty2 00:00:00 i3, with the UID being 1000 (which is my UID). So I think it's being run by me. Changing ~ to an absolute path also doesn't seem to make a difference, I'm afraid. It does make me realise however that it's finding the display script which is in ~/bin, i.e. my PATH is being loaded correctly. Which is even more strange, since it's not loading other environment variables from startup. Sep 7, 2019 at 8:51
0

This was answered for me on Reddit. The problem is that .bashrc is only loaded by bash - putting the environment variables in ~/.profile means that it runs correctly.

2
  • Well ~/.profile is loaded by bash as well, but only if there is no ~/.bash_profile and if the shell is started as a login shell. The sh shell should also read ~/.profile if it's started as a login shell. It's unclear what shell is running your i3 config file. Also, wouldn't running feh as a background job like that leave a lot of feh processes hanging around after a while?
    – Kusalananda
    Sep 7, 2019 at 11:19
  • I happened to check this, it seems to use /bin/sh. I don't think it will run many fehs, since the script is in the i3config file, which is only loaded once when i3 starts. Sep 8, 2019 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.