查看当前bash版本

/bin/bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin20)
Copyright (C) 2007 Free Software Foundation, Inc.

升级bash

  • 命令:brew install bash
  • 查看当前系统bash
which -a bash
/usr/local/bin/bash		# 新安装bash
/bin/bash		# 旧bash
  • 查看新bash版本
/usr/local/bin/bash --version
GNU bash,版本 5.1.16(1)-release (x86_64-apple-darwin20.6.0)
Copyright (C) 2020 Free Software Foundation, Inc.

设置默认bash

  • 执行sudo vim /etc/shells将新的/usr/local/bin/bash加到最后一行
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
/usr/local/bin/bash
  • 将bash切到最新版本
chsh -s /usr/local/bin/bash
Changing shell for zsx.
Password for zsx:

安装 bash-completion

  • 执行命令:brew install bash-completion@2
  • 将命令输出显示内容添加到~/.bash_profile
export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
  • 导入source kuberctl的补全脚本
echo 'source <(kubectl completion bash)' >>~/.bash_profile

验证补全功能

  • 重启shell
  • 重试kuberctl补全功能
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐