linux - 指向可执行文件的符号链接(symbolic link)不会启动应用程序,错误 : <symlink> doesn't exist

标签 linux bash

我有一个指向可执行文件的符号链接(symbolic link),我按如下方式创建了它:

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

如果在命令行输入:

$ /home/x/app/wps_office/wps

然后我的应用程序可以正确启动,但是如果我尝试通过符号链接(symbolic link)启动我的应用程序,则会收到以下错误:

$ wps
wps does not exist!

只是为了确定符号链接(symbolic link)是否正确;

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

文件夹/home/x/bin 是我创建符号链接(symbolic link)的地方,这个文件夹包含在我的 $PATH 变量中。

我看不出这里出了什么问题,为什么我的应用程序在我使用符号链接(symbolic link)时不执行?

快速更新;

我刚刚快速查看了符号链接(symbolic link)指向的文件的内容,看起来消息 wps does not exist 实际上来自应用程序,这意味着符号链接(symbolic link)实际上是正确的。我不知道确切的原因,因为我觉得很奇怪,当我不使用符号链接(symbolic link)时一切正常。我需要更仔细地查看代码才能找到答案。

符号链接(symbolic link)指向的文件的代码:

#!/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 "$@"

请注意它说 echo "${gApp} does not exist!" 的行,这就是我的错误来源。

最佳答案

如果命令是 shell 的一部分,或者如果它们在 PATH 环境变量中,则命令将只在没有任何路径元素的情况下执行。尝试 ./wps 在符号链接(symbolic link)所在的目录中。还要确认权限是否正确。

关于linux - 指向可执行文件的符号链接(symbolic link)不会启动应用程序,错误 : <symlink> doesn't exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25220803/

相关文章:

linux - (g)awk 似乎会缓存 shell 命令的输出 - 如何避免这种情况?

linux - Bash cut 不使用 stdin

linux - bash : Add an option to an existing command

bash - 奇怪的 grep 行为

linux - 加密 config.properties 文件中的密码

linux - xargs : "bash -c" does not pass arguments to command 中的 bash 别名

linux - Linux环境下ASP.NET Core网站文件放在哪里

linux - Makefile:3: *** 缺少分隔符。停止

linux - 是否可以在 eclipse/linux 中将最新的 firefox(firefox/26.0) 设置为 eclipse 内部 Web 浏览器?

string - 如何防止 vim 在字符串中添加缩进?