This forum has been archived. All content is frozen. Please use KDE Discuss instead.

PATH missing $HOME/bin running a script from a panel icon

Tags: None
(comma "," separated)
User avatar
josephj
Registered Member
Posts
35
Karma
0
OS
I hope this is the right place to ask this. Please redirect me if it is not.

I have a small project on sourceforge written in bash using yad for GUI access. I add it to the Application Menu and from there, add it to my panel.

When I run my script from a terminal, everything works fine. And, everything worked fine from the KDE 4 desktop in 12.04 and earlier.

Now, in Kubuntu 16.04, it fails because some of my scripts call other scripts (using just the basename of the script) and can't find them because PATH doesn't include $HOME/bin where the other script lives.
It works from a terminal, because that directory is added to my path in .bashrc.

How do I fix this?

I don't really want to change all calls in my scripts to full paths if I don't have to.

I also have a bunch of users for my project (no idea exactly how many) and I make them do too many things to install it already, so I don't really want to have them have to add a script somewhere like ~/.kde/env to fix the path in a way not all users may appreciate.

Is this a problem with KDE5? There was no such issue in KDE3 or KDE4.

Thanks.
Serafean
Registered Member
Posts
31
Karma
1
OS
Hi,

- You could modify $PATH in the script itself. This way you won't pollute the global $PATH variable.
- You could also modify path in /etc/profile.d/. This has the benefit of not being bash specific.
- you could create a wrapper script that prepares the environment for your real script and launches it.

From personal experience modifying $PATH globally is a really bad idea.
User avatar
josephj
Registered Member
Posts
35
Karma
0
OS
Thanks. I can't think of a better way to get users *really* mad than by altering something so basic as their global PATH.

I was going to do something like PATH=$HOME/bin:$PATH myscript in the menu entry, but your suggestion to actually do it within the script is better. Done once and forget it.

I'll just have to add an entry to my project config file to let users specify where the programs are stored in case it isn't in ~/bin.

Thank you.
Serafean
Registered Member
Posts
31
Karma
1
OS
I'll just have to add an entry to my project config file to let users specify where the programs are stored in case it isn't in ~/bin.

Um, at this point do you still have to play around with $PATH? Couldn't you just use the variable as a prefix to all the calls?

Also I don't think an entry to the config file should be necessary : if your main script is in a directory, and the subscripts are in a predefined subdirectory, couldn't you just use that knowledge?
User avatar
josephj
Registered Member
Posts
35
Karma
0
OS
Better idea again!

It turned out to be a bit convoluted. See:

http://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself

I think I can use:

Code: Select all
script_path=$(dirname "$(realpath -s "$0")")


Thanks.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]