Ubuntuでrootの.bashrcのbash完了設定がコメントアウトされたのはなぜですか?

Ubuntuでrootの.bashrcのbash完了設定がコメントアウトされたのはなぜですか?

私はUbuntu 20.04を使用しており、ルートの.bashrcファイルでbash完了設定がデフォルトでコメントアウトされていることがわかりました。

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
# if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
#     . /etc/bash_completion
# fi

コメントアウトを解除すると、完成が再び機能します。基本的に注釈が付けられたのはなぜですか?これはセキュリティ上の考慮事項に関連していますか?

ベストアンサー1

その理由は、表示されるコードで説明されています。コメントを読む(強調):

プログラム可能な完成を有効にする(/etc/bash.bashrcおよび/etc/profileソース/etc/bash.bashrcですでに有効になっている場合、この機能を有効にする必要はありません。)。

完了は、次のファイルによってUbuntuシステムでデフォルトで有効になります/etc/profile.d/bash_completion.sh

$ cat /etc/profile.d/bash_completion.sh
# Check for interactive bash and that we haven't already been sourced.
if [ -n "${BASH_VERSION-}" -a -n "${PS1-}" -a -z "${BASH_COMPLETION_VERSINFO-}" ]; then

    # Check for recent enough version of bash.
    if [ ${BASH_VERSINFO[0]} -gt 4 ] || \
       [ ${BASH_VERSINFO[0]} -eq 4 -a ${BASH_VERSINFO[1]} -ge 1 ]; then
        [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] && \
            . "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
        if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then
            # Source completion code.
            . /usr/share/bash-completion/bash_completion
        fi
    fi

fi

このファイルは、/etc/profileログインシェルの起動時に読み取られるファイルから始まります。

 $ grep -A6 profile\.d /etc/profile
if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

~/.bashrcつまり、ルートファイルで再度有効にする必要はなく、上記のファイルを介してすでに有効になっています。実際、/etc/bash_completionUbuntuのデフォルト値は次のようになるため、表示されるコードは意味がありません。

$ cat /etc/bash_completion
. /usr/share/bash-completion/bash_completion

これがまさにそれです/etc/profile.d/bash_completion.sh

おすすめ記事