我关注这个博客,设置一个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 "$@"
当我运行源代码~/.zshrc时,我将这些行添加到了~/.zshrc中它在"("附近给出/.zshrc:4:解析错误我读了zsh函数doc,但仍然不太擅长理解语法以及如何解决这个问题。
查看zsh手册页(man zshmisc
(:
[[(]pattern[|pattern]…(列表中的大小写单词(;;|;&|;(]。。。esac
正如您所看到的,您必须通过|
:来分离多个模式
case $1 in
|clear)
....