【问题标题】:executable in PATH not found在 PATH 中找不到可执行文件
【发布时间】:2014-01-14 00:44:47
【问题描述】:

我在 PATH 中有一个可执行文件,但是当我键入命令时找不到它。

$PATH 的结果是: -bash:/Users/aridyckovsky/.rvm/gems/ruby-2.1.0/bin:/Users/aridyckovsky/.rvm/gems/ruby-2.1.0@global/bin:/Users/aridyckovsky/.rvm/rubies /ruby-2.1.0/bin:/Library/Frameworks/Python.framework/Versions/3.3/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin :/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin:/usr/local/mysql/bin:/Users/aridyckovsky/.rvm/bin: 没有这样的文件或目录`

具体来说,我试图在/usr/local/bin 中执行mongod,但结果是-bash: mongod: command not found。但是,我可以在同一位置运行其他可执行文件。有什么想法吗?

【问题讨论】:

  • 那么ls -l /usr/local/bin/mongod 怎么说?
  • 对您的文件执行 'ls -l 完整路径并将其发布到此处。
  • 结果是:lrwxr-xr-x 1 aridyckovsky admin 34 Nov 11 13:43 /usr/local/bin/mongod -> ../Cellar/mongodb/2.4.8/bin/mongod
  • @user3192285 仅仅因为符号链接存在并不意味着实际脚本存在(如果符号链接被破坏,您将得到相同的错误)。你也可以ls -l /usr/local/Cellar/mongodb/2.4.8/bin/mongod
  • 貌似不存在脚本 ls:/usr/local/Cellar/mongodb/2.4.8/bin/mongod: No such file or directory

标签: bash mongodb path


【解决方案1】:

当您尝试将$PATH 作为命令执行时,您会收到该错误。

$ $PATH
bash: /home/glennj/bin:...:/opt/tcl/8.6/bin: No such file or directory

在 bash 中,使用 type 内置函数来查找内容:

$ type mongod
mongod is /usr/bin/mongod

使用type -a 也可以显示别名和函数

$ type -a ls
ls is aliased to `ls -F'
ls is /bin/ls
$ type -a git
git is a function
git () 
{ 
    case "$1" in 
        push | pull)
            if (( $# == 1 )); then
                local branch=$(git_current_branch);
                if [[ -n $branch ]]; then
                    set -- $1 origin "$branch";
                    echo git "$@";
                else
                    echo "You're not in a git-managed directory" 1>&2;
                    return;
                fi;
            fi
        ;;
    esac;
    command git "$@"
}
git is /usr/bin/git

【讨论】:

  • +1 不太确定它是否能回答问题,但类似于hint 类型。知道type > which 用于bash,但不知道a 标志。绝对在我的 bash 上覆盖 which='type -a'。
猜你喜欢
  • 2017-04-28
  • 2019-01-16
  • 2015-01-25
  • 2015-05-19
  • 1970-01-01
  • 1970-01-01
  • 2021-11-23
  • 2017-09-25
  • 2018-10-04
相关资源
最近更新 更多