13

I am creating .desktop files for use in the Unity Launcher.

I have my own location in my home directory where I put my executables (~/usr/bin/) which is correctly added to my PATH environment variable in my .pam_environment file as specified in the relevant Ubuntu documentation.

This is the contents of my .pam_environment file:

LANGUAGE=en_AU:en_GB:en
LANG=en_AU.UTF-8
LC_NUMERIC=en_AU.UTF-8
LC_TIME=en_AU.UTF-8
LC_MONETARY=en_AU.UTF-8
LC_PAPER=en_AU.UTF-8
LC_NAME=en_AU.UTF-8
LC_ADDRESS=en_AU.UTF-8
LC_TELEPHONE=en_AU.UTF-8
LC_MEASUREMENT=en_AU.UTF-8
LC_IDENTIFICATION=en_AU.UTF-8

PATH DEFAULT=${PATH}:~/usr/bin/

Which results in my PATH variable being as follows:

ben@ben-HPdv6:~$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:~/usr/bin/:~/usr/bin/

I know it is appended twice, but anything in the .pam_environment file seems to get added twice no matter what when using the correct syntax recommended in that Ubuntu Documentation I have referenced.

This is one example of the problem (it happens with all cases). I have a script (called eclipse) in ~/usr/bin/ which runs Eclipse IDE.

I can open any terminal and simply type eclipse and it runs fine like you would expect.

But when using the following .desktop file:

#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Name=Eclipse - Juno (4.2)
Icon=/home/ben/.icons/eclipse.svg
Exec=eclipse

I get the error: Error

But when I change the Exec= line to:

Exec=/home/ben/usr/bin/eclipse

it works perfectly.

The Official Unity Launchers and Desktop files documentation suggests that this should work:

Exec is the path to the executable file. The full path to the executable file must be used only in case it isn't in any of the paths specified in the $PATH variable. For example, any files that are inside the path /usr/bin don't need to have their full path specified in the Exec field, but only their filename.

Any suggestions on what is happening?

1
  • Modify your desktop file to fun eclipse in a shell and it may work. I couldn't say since I stopped using portable some time ago. Feb 4, 2013 at 5:51

2 Answers 2

5
+50

The tilde doesn't get expanded in .pam_environment the way it would in a profile script, and desktop files don't do shell expansion on their Exec lines the way the shell would, so it's looking for a file that's literally named ~/usr/bin/eclipse, which of course doesn't exist.

Replace the tilde in the PATH assignment with ${HOME} and it seems to work.

2
  • Your answer is correct, that fixes the problem entirely. Thanks! To save me asking another question, do you have any idea why appending to the $PATH happens twice?
    – btalb
    Feb 6, 2013 at 1:46
  • 1
    It's a bug: pad.lv/955032
    – cscarney
    Feb 6, 2013 at 20:18
3

What is said on the Ubuntu documentation makes sense, however its "not recommended anymore" section is lacking in some details. For that reason, my answer will involve using one of these methods. Also: it is already used for this exact same purpose.

Take a quick visit to your ./.profile file.

Mine contains this:

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

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

As you can see by the last section of this file (lines below # set PATH so it includes user's private bin if it exists), this is already being done. So if you wanted to add something to the $PATH variable, you would simply do the same thing. The documentation did mention that this will be run every time the system is started.

In your case, all you would need to do is add this:

# set PATH to custom variable (this line is not needed)
if [ -d "$HOME/usr/bin" ]; then
    PATH="$HOME/usr/bin:$PATH"
fi

At this point I am starting to think that the only reason that this method is not recommended anymore is it involves scripting on startup, which is very sensitive to slight mistakes. When someone is working with something like this, however, a small mistake could be undone simply by changing the file back to the way it was.

If you are not sure how to do this:

1) First, press CTRL+ALT+F3

2) Log in by following the onscreen prompt

3) Type this into the command prompt:

/usr/bin/nano ./.profile

4) remove these lines: (we just added them)

# set PATH to custom variable (this line is not needed)
if [ -d "$HOME/usr/bin" ]; then
    PATH="$HOME/usr/bin:$PATH"
fi

5) press CTRL+O (as in Out)

6) press CTRL+X (as in eXit)

7) type exit and press ENTER (sometimes RETURN)

8) now press CTRL+ALT+F7

9) You should get your login screen or desktop, depending on when the problem occured. If not, press CTRL+ALT+DEL (sometimes CTRL+ALT+DELETE) and your system should restart safely.

Hope this helps!

1
  • Both solutions work to fix the problem, so thanks :) I have upvoted you both but @csarney explains the exact reason for the problem and uses the environment variable setting method recommended in the documentation, so I have marked that as the solution.
    – btalb
    Feb 6, 2013 at 1:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .