Gio
Gio

Reputation: 3340

symlink to executable doesn't launch application, error: <symlink> doesn't exist

I have a symlink to an executable, which I've created as follows:

$ ln -s /home/x/app/wps_office/wps

If on the commandline I type:

$ /home/x/app/wps_office/wps

Then my application launches correctly, but if I try to launch my application through the symlink, then I get the following error:

$ wps
wps does not exist!

Just to make sure if the symlink is correct;

$ readlink wps
/home/x/app/wps_office/wps

The folder /home/x/bin is where I've created the symlink, this folder is included in my $PATH variable.

I don't see what is going wrong here, why doesn't my application execute when I use the symlink?

Quick update;

I've just quickly looked trough the contents of the file where the symlink is pointing to, it looks like the message wps does not exist is actually coming from the application, meaning the symlink is actually correct. I don't know the exact reason why, as I find it strange that everything works correctly when I don't use the symlink. I need to look more thorougly to the code to find that out.

The code of the file where the symlink is pointing to:

#!/bin/bash

gOpt=
gTemplateExt=("wpt" "dot" "dotx")
gBinPath=$(dirname "$0")
if [ -d "${gBinPath}/office6" ]; then
    gInstallPath=${gBinPath}
else
    gInstallPath=/opt/kingsoft/wps-office
fi
gApp=wps

function parse_arg()
{
    if [ $# -eq 1 ] ; then
        ext="${1##*.}"
        if [ "" = "${ext}" ] ; then
            return 0
        fi

        for i in ${gTemplateExt}
        do
            if [ "${ext}" = "${i}" ] ; then
                gOpt=-t
            fi
        done
    fi
}

function run()
{
    oldPwd="${PWD}"
    if [ -e "${gInstallPath}/office6/${gApp}" ] ; then
        if [ -d /usr/lib32/gtk-2.0 ]; then
            export GTK_PATH=/usr/lib32/gtk-2.0
        fi
        ${gInstallPath}/office6/${gApp} ${gOpt} "$@" || ${gBinPath}/wps_error_check.sh ${gInstallPath}/office6/${gApp}
    else
        echo "${gApp} does not exist!"
    fi
}

function main()
{
    parse_arg "$@"
    run "$@"
}

main "$@"

Note the line where it says echo "${gApp} does not exist!", this is where my error is coming from.

Upvotes: 1

Views: 1441

Answers (3)

Gio
Gio

Reputation: 3340

The file where the symlink was pointing to, takes the current directory to launch a different file. This is the file actually being launched. The issue can be solved by simply creating a symlink to this file, which means a symlink to /home/x/app/wps_office/office6/wps

Another option is to edit the source file itself, as explained by @Pixelchemist. However as it concerns an application which I've downloaded and which I will probably update in the future, I think in this case that is not a preferred option.

Upvotes: 0

Pixelchemist
Pixelchemist

Reputation: 24946

Change the line

gInstallPath=/opt/kingsoft/wps-office

in the script to

gInstallPath=/home/x/app/wps_office

Upvotes: 1

roelofs
roelofs

Reputation: 2170

Commands will only be executed without any path elements if they're part of the shell, or if they're in the PATH environment variable. Try ./wps in the directory where the symlink is. Also confirm that the permissions are correct.

Upvotes: 2

Related Questions