3

gmrun started ignoring the PATH variable I defined in ~/.bashrc for no obvious reason. Anyone has any idea how I can find out a way to solve this annoying problem?

EDIT

I have not found the solution, but I ended up switch to bashrun2, which does what I need it to do.

Anthon
  • 79,293
qed
  • 2,669

3 Answers3

4

gmrun inherits the $PATH variable set by the parent that spawned it. Hence, you can make it source ~/.bashrc by initiating it with:

bash -ci 'gmrun'

This creates an "interactive" shell; this has a few differences to a non-interactive shell, but works perfectly fine with gmrun. Simply bind the command above to your hotkey.

Sparhawk
  • 19,941
4

the PATH variable I defined in ~/.bashrc

There's your problem right there. .bashrc is an initialization file for interactive shells. Gmrun doesn't start an interactive shell, it starts the program you tell it to start. So your PATH is never getting set. In fact, in order to get completion in gmrun, you need the PATH environment variable to be set in the environment that you run gmrun in.

Set PATH in the right place: ~/.profile. This file is read when your session starts. That's where you should define your environment variables.

Don't read .profile from .bashrc or vice versa. They have completely different purposes and are used in different purposes.

Due to a quirk of bash, .bashrc isn't read in an interactive login shell, so you should write a .bash_profile that loads the other two for this case:

. ~/.profile
case $- in *i*) . ~/.bashrc;; esac

See Is there a ".bashrc" equivalent file read by all shells? and the other posts I cite there for more details.

1

.bashrc is an initialization file for interactive non login bash instances, I doubt whatever is setup there has ever been taken into account by gmrun when not launched from such a shell instance.

If your desktop environment is setup so that any bash initialization file is taken into account, it should be your .profile or .bash_profile one, and you need to quit and restart your desktop environment before modifications are effective from processes launched by the environment.

AProgrammer
  • 2,318
  • Thanks. But my .profile sources .bashrc, it should be a problem, right? – qed Jul 30 '13 at 13:55
  • @CravingSpirit, I do it only if the shell is interactive (PS1 set) as what I've in my .bashrc make sense only for interactive shells (so there is no environment variable definition in my .bashrc, in my experience those who set environment variables definition in their .bashrc are better served by setting the option which make launch shells from their terminal emulator as login shells). – AProgrammer Jul 30 '13 at 14:37
  • Testing PS1 doesn't tell you anything about whether the shell is interactive. I know this is all over the web, I have no idea where it comes from, it's plain wrong. There's a reliable, portable way to determine whether a shell is interactive: test whether $- contains i. – Gilles 'SO- stop being evil' Jul 31 '13 at 01:02
  • @Gilles, one potential source is the bash info manual ;-). At least in edition 3.2, that is given as an alternative way to testing $-. I don't remember why I ended up preferring it to testing $- (I traced back my use to 1999 which is the earlier revision I've not lost) – AProgrammer Jul 31 '13 at 07:02