我的“导出路径=”丢失了什么?

Jer*_*ith 0 linux bash mac-osx

我在 Mac OSX Lion 上,不知何故在安装 mysql 和 postgres 时,我的 .bash_profile 上的导出 PATH 行被弄乱或删除。

所以我在一个空的 .bash_profile 中添加了这个:

export PATH=/usr/local/bin:/usr/sbin:/usr/local/sbin:/usr/bin
Run Code Online (Sandbox Code Playgroud)

但是我无法执行任何 bash 命令:

 /usr/bin $ ls
-bash: ls: command not found

 /usr/bin $ /bin/echo $PATH
/usr/local/bin:/usr/sbin:/usr/local/sbin:/usr/bin
Run Code Online (Sandbox Code Playgroud)

我的 .bashrc 可能但不相关,但以防万一:

[[ -s "/Users/jer/.rvm/scripts/rvm" ]] && source "/Users/jer/.rvm/scripts/rvm"

function _git_prompt() {
    local git_status="`git status -unormal 2>&1`"
    if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
        if [[ "$git_status" =~ nothing\ to\ commit ]]; then
            local ansi=42
        elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then
            local ansi=43
        else
            local ansi=45
        fi
        if [[ "$git_status" =~ On\ branch\ ([^[:space:]]+) ]]; then
            branch=${BASH_REMATCH[1]}
            test "$branch" != master || branch=' '
        else
            # Detached HEAD.  (branch=HEAD is a faster alternative.)
            branch="(`git describe --all --contains --abbrev=4 HEAD 2> /dev/null ||
                echo HEAD`)"
        fi
        echo -n '\[\e[0;37;' "$ansi"';1m\]'"$branch"'\[\e[0m\] '
    fi
}
function _prompt_command() {
    PS1="\n `_git_prompt`"'\n \[\e[1;34m\]\w \$\[\e[0m\] '
}
PROMPT_COMMAND=_prompt_command
#export PS1='\n\[\033[1;33m\]\w\n\[\033[0m\]$(parse_git_branch)$ '
Run Code Online (Sandbox Code Playgroud)

841*_*104 7

/bin也可能失踪了/sbin

user@host ~ $ which ls
/bin/ls
Run Code Online (Sandbox Code Playgroud)

  • 更详细地说,你的`PATH` 通常应该包含:`/bin`、`/sbin`、`/usr/bin`、`/usr/sbin`、`/usr/local/bin`、`/usr /local/sbin`,然后是您想要搜索的任何其他地方。(列出的顺序是我的首选顺序。我还看到了在 `sbin` 路径之前列出的所有 `bin` 路径,我也不介意。) (2认同)
  • 更详细地说,这是 Lion 上的默认路径:`/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin` (2认同)