Linux

我的’export PATH=‘缺少什麼?

  • February 14, 2012

我在 Mac OSX Lion 上,不知何故在安裝 mysql 和 postgres 時,我的 .bash_profile 上的 export PATH 行搞砸了或被刪除了。

所以我在一個空的.bash_profile中添加了這個:

export PATH=/usr/local/bin:/usr/sbin:/usr/local/sbin:/usr/bin

但我無法執行任何 bash 命令:

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

/usr/bin $ /bin/echo $PATH
/usr/local/bin:/usr/sbin:/usr/local/sbin:/usr/bin

我的 .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)$ '

/bin也可能失踪了/sbin

user@host ~ $ which ls
/bin/ls

引用自:https://serverfault.com/questions/360092