【发布时间】:2019-10-30 02:07:38
【问题描述】:
我正在关注这个博客来设置一个 zsh 函数来切换 aws cli 配置文件 :https://mads-hartmann.com/2017/04/27/multiple-aws-profiles.html
这是博客中的zsh函数:
function aws-switch() {
case ${1} in
"")
clear)
export AWS_PROFILE=""
;;
*)
export AWS_PROFILE="${1}"
;;
esac
}
#compdef aws-switch
#description Switch the AWS profile
_aws-switch() {
local -a aws_profiles
aws_profiles=$( \
grep '\[profile' ~/.aws/config \
| awk '{sub(/]/, "", $2); print $2}' \
| while read -r profile; do echo -n "$profile "; done \
)
_arguments \
':Aws profile:($(echo ${aws_profiles}) clear)'
}
_aws-switch "$@"
当我运行 source ~/.zshrc 时,我将这些行添加到我的 ~/.zshrc 它给出 /.zshrc:4: parse error near `)' 我阅读了 zsh 函数文档,但仍然不太擅长理解语法以及如何解决这个问题。
【问题讨论】: