2

I have this desktop entry:

[Desktop Entry]
Name=dummy
Type=Application
Terminal=false
Icon=/home/xyz/Software/Test/ico.png
Exec= /home/xyz/Software/Test/start

which is supposed to execute file containing:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./Linux/lib 
exec ./foo --gc=sgen

I have tried creating symlink, but result is the same - it does nothing. When I double click the file in it's folder, it gives me prompt like this:

http://1.bp.blogspot.com/-hfJadnx7lM8/T_qkxu6wanI/AAAAAAAABtM/TBiFSfVzJeg/s1600/2012-07-09-162344_514x187_scrot.png

After I click Run it runs fine, but when executing from desktop...

I've tried exporting this path to PATH, but when running foo, it can't find some library even tough it should... Also path is 100% correct, because icon is appearing as it should.

What I'm trying to do, is creating working desktop shortcut of start file, or foo file (which won't execute without error for some reason, I have added it's path to PATH, maybe missing argument '--gc=sgen' when executing ?)

Any help will be greatly appreciated!

  • Where does "script.sh" come from? It doesn't appear anywhere but the screenshot. – Michael Homer Oct 17 '15 at 21:21
  • It's just sample picture of that prompt from the internet... not actual screenshot, but it looks the same. – RiddleMeThis Oct 17 '15 at 21:26
  • Does the article from which the image comes answer your question? – Michael Homer Oct 17 '15 at 21:29
  • There's a bit of a jumble of possible questions at the bottom of the post - maybe you can edit with more specifics of which problem you're trying to solve right now. – Michael Homer Oct 17 '15 at 21:29
  • I have tried this already without success :/. But still... I don't want to disable this prompt (for the sake of security), if not necessary. – RiddleMeThis Oct 17 '15 at 21:31
3

The problem is that you're using relative paths in the script: ./Linux/lib, ./foo. These paths are relative to the current directory. The current directory of the process running the script is the current directory of whatever process launched it; it has nothing to do with the location of the script. When you run the script by clicking a desktop icon, the current directory is your home directory.

One solution is to add a cd command in the script, to change to the directory where the application is installed.

#!/bin/sh
cd /home/xyz/Software/Test/
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:./Linux/lib"
exec ./foo --gc=sgen

But it would be more useful to not change the current directory, and instead use absolute paths. This way you can use the script to open files in the current directory, for example. While I'm at it, I added "$@" to the invocation of foo, which passes the arguments on the script's command line on to the application.

#!/bin/sh
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/xyz/Software/Test/Linux/lib"
exec /home/xyz/Software/Test/foo --gc=sgen "$@"

If the script is located in the application directory, you can make it detect its own location. $0 is the path to the script. ${0%/*} is the path to the script with everything after the last slash stripped off, i.e. the path to the directory containing the script.

#!/bin/sh
foo_directory="${0%/*}"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$foo_directory/lib"
exec "$foo_directory/foo" --gc=sgen "$@"

Beware that if LD_LIBRARY_PATH is initially empty, you're adding the current directory, which may not be a good idea. You should test it.

#!/bin/sh
foo_directory="${0%/*}"
if [ -n "$LD_LIBRARY_PATH" ]; then
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$foo_directory/lib"
else
  export LD_LIBRARY_PATH="$foo_directory/lib"
fi
exec "$foo_directory/foo" --gc=sgen "$@"

or (assuming you don't use empty entries in LD_LIBRARY_PATH, which is a sane choice)

#!/bin/sh
foo_directory="${0%/*}"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$foo_directory/lib"
LD_LIBRARY_PATH="${LD_LIBRARY_PATH#:}"
exec "$foo_directory/foo" --gc=sgen "$@"
| improve this answer | |
  • Thanks a bunch, let me process it first :D... I'll give it a try! – RiddleMeThis Oct 17 '15 at 21:39
  • I've tried your first suggestion and it works like charm. Thank you! – RiddleMeThis Oct 17 '15 at 21:44

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.