Can't call scripts from i3, but I can call them just fine from term?

Been using manjaro w. i3 for a while and now transitioned to Endeavour, also w. i3 - one step closer to perfection :slight_smile: One strange thing though, in my i3-config file, I can’t execute scripts. I can execute them just fine from terminal.

simple example - launching a webbrowser this way works fine:

bindsym $mod+q exec --no-startup-id qutebrowser

but this

bindsym $mod+q exec --no-startup-id test-i3-execute-script.sh

does not - even though it just contains


#!/bin/bash
qutebrowser

I have of course made it executable:

chmod +x $HOME/bin/test-i3-execute-script.sh

The script works from a terminal, but not from within i3. It’s the same with all my scripts, that in a dropbox folder and symlinked to $HOME/bin.

It must be something with the $PATH? OR what? What am I overlooking here?

~/.local/share/gem/ruby/3.0.0/bin:~/.npm-global/bin:/usr/local/stata17:/home/emil/.yarn/bin:/home/emil/.cargo/bin:/home/emil/bin:/home/emil/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/opt

would be grateful for any assistance.

Add full path inside the script. Does that work?
And welcome to the forum! :smile:

1 Like

Yes that does work, tried it but forgot to write it! However, some of the scripts calls other scripts within them, and those scripts are then not useable either. I’d like to avoid having absolute paths as a standard in my scripts if I can avoid it :slight_smile:

tthank you! :smiley:

I assume there is a way, but I’m not that familiar with i3 configs.
Hopefully someone will chime in to help.

Why? That’s the simplest and most elegant solution here.

If you are not going to use absolute paths, you’ll need to define your PATH environment variable in the script. It does not source your .bashrc. Or you can add source ~/.bashrc to the beginning of your script, which is a rather clumsy solution.

Well I came from Manjaro, where the $HOME/bin was possible to execute through i3. So I assumed that was a standard thing. So when I go to Endeavour, I assume that $HOME/bin is also in he PATH (which it is, in my .zshrc and .bashrc files). It doesn’t seem unelegant to me that there is a folder in the $HOME dir where you can put scripts and expect them to be executable by something like i3, (without admin rights, of course), is it? Seems elegant to me, but if you can tell me why that’s a bad idea I’d be happy to learn something new! What if the directory structure changes? Isn’t the whole idea with a $PATH that you tell it where your executables are, exactly to get rid of absolute paths that are fragile because they can change?

What I’m mostly interested it, though, is understand why I could execute scripts in i3 on manjaro linux and not on endeavour. Where is i3 sourcing the $PATH from that is different from manjaro linux ?

Because on Manjaro you probably set the PATH variable elsewhere. Where? I don’t know, it’s your system, you should know that. Probably in .bash_profile?

It looks like Manjaro has a little script in /etc/profile.d that adds it to the path. Here is the script: https://gitlab.manjaro.org/packages/core/filesystem/-/blob/master/home-local-bin.sh Here is where it gets added to /etc/profile.d: https://gitlab.manjaro.org/packages/core/filesystem/-/blob/master/PKGBUILD#L86

It’s a good solution I think. Go ahead and set it up for yourself and you should be all set to use ~/.local/bin in your i3 config.

/etc/profile.d/home-local-bin.sh
case ":${PATH}:" in
  *:"$HOME/.local/bin":*) ;;
  *) export PATH="$HOME/.local/bin:$PATH" ;;
esac

well excuse me for only being an intermediate user, that is why I wrote it here in the ‘newbie’ forum. - I’m trying my best to learn you know!

Thank you so much, I’m learning something from this. Could you tell me, if you have the time, how you backtracked this? what was your line of reasoning to get at the conclusion? I appreciate the answer and I would like even more to get better at troubleshooting these things myself!

Folder /etc contains configuration stuff for many things, including shell initialization.
/etc/profile.d and /etc/profile are some of those places.

/etc/profile.d was my suspicion before I even looked (because that is how I would set it). It was just a matter of taking a peek to check if I was right.

/etc/profile.d is a great place to set environment variables because it will honor a script if you put it there. This means you don’t have to blatantly set an environment variable like you would in /etc/environment, instead you can set up something conditional. I recently added something for Garuda Linux Gnome, where if the user launches a Wayland session it will set a couple environment variables for them but if they are using X11 it will not (https://gitlab.com/garuda-linux/themes-and-settings/settings/garuda-gnome-settings/-/blob/master/etc/profile.d/environment.sh), so it was somewhat fresh in my head already.

1 Like

I see, that is very useful.

It’s not really working, though - I made a script with the content:


case ":${PATH}:" in
   *:"$HOME/.local/bin":*) ;;
   *) export PATH="$HOME/.local/bin:$PATH" ;;
esac

and put it here:

/etc/profile.d/home-local-bin.sh

however the $HOME/bin is not in the $PATH by default (by running ECHO $PATH without adding anything in .bashrc), and neither is $HOME/.local/bin.

This is how the $PATH looks like:


/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl


I also tried adding

#!/bin/bash

at the top, and also

sudo chmod +x

But to no avail.

Try logging out and logging back in, those scripts get loaded during the login process.

Already tried that, but thanks :slight_smile:

Quite strange actually. I have another system running Ubuntu which uses Xfce with i3wm as window manager, in my i3wm config I just use the command I need and if it’s in my user’s path it will just open. Maybe try adding the PATH to your scripts?

Should modify it a bit:

case "$PATH" in
   $HOME/.local/bin) ;;
   $HOME/.local/bin:*) ;;
   *:$HOME/.local/bin) ;;
   *:$HOME/.local/bin:*) ;;
   *) export PATH="$HOME/.local/bin:$PATH" ;;
esac

Not pretty, but should be better (note I didn’t test it… :wink:).

Edit: actually this is likely not any better than the original. Sorry about that.

It needs to be a login shell.

Try

bash -l

to see if it works.

See man bash for more.

Edit: alternatively, you could edit file /etc/bash.bashrc and add the PATH setting there.

Welcome,

A web search shows that distributions like Ubuntu or Fedora use ~/.profile to add ~/bin to the path.

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

I just tested it on my machine and it works as expected. Do you have executable files in ~/.local/bin? If not, it doesn’t do anything.