iTerm2:當我嘗試取得設定檔時出現奇怪的錯誤訊息

iTerm2:當我嘗試取得設定檔時出現奇怪的錯誤訊息

iTerm2 3.0.15
作業系統 X 10.11.6

我最近嘗試在全新安裝後配置我的終端。我的問題是,當我這樣做時,我收到一個奇怪的錯誤訊息。我進入我的 .bash 目錄;其中,我有幾個設定文件,命名如下:aliases、bash_profile、exports、extras、functions、inputrc、path 和prompt。

當我做:

source bash_profile

我收到此錯誤訊息:

-bash: book: command not found

我對每個設定檔都收到完全相同的錯誤訊息。

我有兩個問題:

  1. 我的 bash_profile 檔案沒有來源,就像我嘗試的任何其他設定檔一樣

  2. 我很確定配置我的終端是基礎,但我不明白錯誤訊息的真正含義。我知道該命令有問題,book但我無法獲得有關它的任何有價值的資訊。

我嘗試過的事情:

  • 終端命令:man bookbook --help、 或help book告訴我該book命令不存在或沒有手動輸入。只info book給了我一個結果,但看起來它與info命令的關係比命令更相關bookbook我的設定檔中也沒有提及任何內容。

  • 谷歌搜尋“bash:book:找不到命令”不會返回太多,當然有很多“找不到命令”,但唯一的參考book是 Bash-it 的 Github 存儲庫上的帖子。大多數關於未找到命令的答案都是關於 PATH 環境變數的,但即使我手動輸入路徑,如下所示(我希望這是正確的方法):

    export PATH=~/.rbenv/shims:/usr/local/Cellar:/usr/local/bin:/usr/local/sbin:/usr/local/bin/flake8:/usr/local/bin/git:/usr/bin:/bin:/usr/sbin:/sbin
    

    之後,當我再次嘗試 a 時source bash_profile,我得到相同的結果-bash: book: command not found

  • Terminal.app 也有同樣的問題。

我的 bash_profile 檔案:

#--------------------------------------------------------------------------#

# B A S H _ P R O F I L E

#--------------------------------------------------------------------------#

# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc

# Load the shell dotfiles, and then some:
# * ~/.path can be used to extend `$PATH`.
# * ~/.extra can be used for other settings you don’t want to commit.
for file in ~/.bash/{path,prompt,exports,aliases,functions,extra,inputrc}; do
    [ -r "$file" ] && [ -f "$file" ] && source "$file";
done;
unset file;

# Enable iTerm 2 Shell Integration
source ~/.iterm2_shell_integration.`basename $SHELL`

# Case-insensitive globbing (used in pathname expansion)
shopt -s nocaseglob;

# Append to the Bash history file, rather than overwriting it
shopt -s histappend;

# Autocorrect typos in path names when using `cd`
shopt -s cdspell;

# Do not autocomplete when accidentally pressing Tab on an empty line.
shopt -s no_empty_cmd_completion

# Enable tab completion for `g` by marking it as an alias for `git`
if type _git &> /dev/null && [ -f /usr/local/etc/bash_completion.d/git-completion.bash ]; then
    complete -o default -o nospace -F _git g;
fi;

# Add tab completion for many Bash commands
#if which brew > /dev/null && [ -f "$(brew --prefix)/share/bash-completion/#bash_completion" ]; then
#   source "$(brew --prefix)/share/bash-completion/bash_completion";
#elif [ -f /etc/bash_completion ]; then
#    source /etc/bash_completion;
#fi;

# Thanks to @tmoitie, adds more tab completion for bash,
# also when hitting tab twice it will show a list.
#if [ -f $(brew --prefix)/etc/bash_completion ]; then
#    . $(brew --prefix)/etc/bash_completion
#fi

# R U B Y
# Ensure rbenv will be used first
# eval "$(rbenv init -)"
# test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash" 

答案1

我最終透過 Homebrew 安裝了 Bash 4.4.19 並編輯了 iTerm 首選項來使用它。我通過在名稱前面添加一個點來重命名我的配置文件,令我驚訝的是它起作用了,即當我手動獲取配置文件時,iTerm 反映了這些更改。

我不知道直接重命名我的文件是否會獲得相同的結果,或者新版本的 Bash 引起的更改是否是它最終起作用的原因。我不太了解 bash,但我想有一個預設配置不知何故搞砸了,並使用全新安裝的新版本及其自己的預設配置已經足夠工作了。

經過一番使用後,我意識到 iTerm 不會在啟動時自動載入 .bash_profile 檔案。幸運的是,我找到了一個解決方案:在應用程式的首選項中,您可以指定在哪裡查找可執行文件,您可以添加一個在啟動時執行的命令。source ~/.bash_profile將完成這項工作,直到找到更好的解決方案。

相關內容