Bash终端 - .profile不会调用终端

时间:2017-03-03 22:09:28

标签: linux bash shell

我很难在我的.profile中使用我的一些功能来工作。

我经常在我的终端中打开文件,复制命令然后在终端中粘贴它。所以,命令可以工作。

但是当我直接在终端输入时,只有大约一半的功能有效。另一半给我一个错误:-bash:   npm: command not found-bash: Load: command not found

特别是两个真正让我感到烦恼的是set_registry_altreload。我无法访问这些但我可以访问set_registry_npm。是否有一些我错过的导致.profile不一致的内容?有没有办法确保我没有一些隐藏的字符导致问题?

这是我的代码:

    variables=(
  "HTTP_PROXY"
  "HTTPS_PROXY"
  "ALL_PROXY"
  "all_proxy"
  "https_proxy"
)

function reload () {
  source ~/.profile
}

function set_registry_npm {
  npm config set registry="https://registry.npmjs.org/"
}

function set_registry_alt {
  npm config set registry="link_that_works_but_removed_for_StackOverflow"
}

function load_proxy_full {
  echo -n "Enter Username: "
  read username
  echo -n "Enter your Password: "
  read -s password
  url=http://${username}:${password}@proxy-change.xxxx.com:8080

  npm config set https-proxy ${url}
  npm config set proxy ${url}

  export HTTP_PROXY=${url}
  export HTTPS_PROXY=${url}
  export ALL_PROXY=${url}
  export all_proxy=${url}
  export https_proxy=${url}

  npm config delete registry
}

function unload_proxy {
  unset ${variables[@]}
  npm config delete https-proxy
  npm config delete proxy
}

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" 

  function parse_git_branch {
    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
  } 

  # This allows git autocomplete
    if [ -f ~/.git-completion.bash ]; then
       . ~/.git-completion.bash
    fi 

    # Node Path from Homebrew I believe
    export NODE_PATH="/usr/local/lib/node_modules:$NODE_PATH"

    export VISUAL="subl -w"
    export SVN_EDITOR="subl -w"
    export GIT_EDITOR="subl -w"
    export EDITOR="subl -w"

function desktop {
  cd /Users/$USER/Desktop/$@
}

# Aliases
  alias l='ls -lah'

  # Git
  alias gcl="git clone"
  alias gst="git status"
  alias gpl="git pull"
  alias gp="git push"
  alias gd="git diff | mate"
  alias ga="git add"
  alias gcm="git commit -m"
  alias gb="git branch"
  alias gba="git branch -a"
  alias gcam="git commit -am"
  alias gbb="git branch -b"
  alias glol="git log --oneline --decorate --all --graph"


# Case-Insensitive Auto Completion
  bind "set completion-ignore-case on" 


  # via homebrew
  if [ -f `brew --prefix`/etc/bash_completion ]; then
    . `brew --prefix`/etc/bash_completion
  fi

export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools

export PATH="$PATH:`yarn global bin`"

[[ -s "/Users/$USER/.rvm/scripts/rvm" ]] && source "/Users/$USER/.rvm/scripts/rvm"  # This loads RVM into a shell session.

2 个答案:

答案 0 :(得分:2)

答案分为两部分:

  1. @barmar指出此错误消息在npm -bash:   npm: command not found之前有一个空格,并且有一个不可见的空间需要删除。

  2. Load RVM into a shell session *as a function*应该是评论,因此缺少#

  3. 这两件事修复了我的.profile

答案 1 :(得分:0)

这一行错了:

Load RVM into a shell session *as a function*

你应该删除它。