iTerm2: 設定ファイルをソースしようとすると奇妙なエラーメッセージが表示される

iTerm2: 設定ファイルをソースしようとすると奇妙なエラーメッセージが表示される

iTerm2 3.0.15
OS X 10.11.6

最近、クリーン インストール後にターミナルを設定しようとしました。問題は、それを実行すると、奇妙なエラー メッセージが表示されることです。.bash ディレクトリに移動します。その中に、aliases、bash_profile、exports、extras、functions、inputrc、path、prompt という名前が付けられたいくつかの設定ファイルがあります。

私がする時:

source bash_profile

次のエラーメッセージが表示されます:

-bash: book: command not found

どの構成ファイルでもまったく同じエラー メッセージが表示されます。

2つの問題があります:

  1. 私のbash_profileファイルは、私が試した他の設定ファイルと同様にソース化されていません

  2. 端末を設定することが基本であることは確かですが、エラー メッセージが実際に何を意味するのか理解できません。そのbookコマンドに問題があることは理解していますが、それに関する有益な情報を得ることができません。

試したこと:

  • ターミナル コマンド: man book、、book --helpまたは は、コマンドが存在しないか、手動エントリがないことをhelp book通知しました。結果のみが示されましたが、コマンドよりもコマンドに関連しているように見えます。また、構成ファイルにも何も記載されていません。bookinfo bookinfobookbook

  • Google 検索で「bash: book: command not found」と検索しても、あまり結果は返されません。もちろん、「command not found」はたくさん出てきますが、唯一参照できるのはbookBash-it の Github リポジトリの投稿です。command not found に関する回答のほとんどは 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
    

    その後、もう一度試してみても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より良い修正方法が見つかるまで作業を続けたいと思います。

関連情報