PDA

View Full Version : KDE Menu launches bash scripts without environment variables



Iskendar
Mar 23rd 2012, 02:03 PM
Hi all,

Trying to set up a little OpenCV demo for our open door at work, so I wanted to launch a bunch of scripts from the desktop. Tried adding them to the start menu, didn't work. Set 'Run in terminal' with the option --noclose, and then I saw that obviously some paths were missing. Apparently the shell starts without running .bashrc, so none of the environment variables are set (checked this). Clicking the script in dolphin or a folder view: same problem.
If I just start up a terminal and run the script from the command line, it works no problem. What am I missing here?

SecretCode
Mar 23rd 2012, 02:48 PM
I think that's by design, for security.

The best practice is probably to edit the scripts so that the path is set, or better (more secure but less portable), to make all references absolute and not rely on $PATH at all.

Or you could change the command in the KDE menu editor to set PATH first
PATH=/usr/bin:/home/name scriptcommand
or something that. This is standard practice when a command needs a particular environment variable set first.

Or write a new script that does the same, or calls ~/.bashrc then your other scripts if you really need all the environment variables set.

Iskendar
Mar 23rd 2012, 02:59 PM
Well, I need multiple paths to be set. Some of the demo's need various python paths, I also need an IPcam's URL etc...
I tried writing a small script like this:

#!/bin/bash
bash /home/me/.bashrc
echo $DEMO #one of the paths set in .bashrc

And put

/home/me/demo/callbashrc; /home/me/demo/democode

into the 'Command' field of the menu editor.
The 'echo $DEMO' line remains blank, so it doesn't read the environment variables, and the second script is executed but again, lacks the necessary variables.