Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“)'附近的zsh函数用例条件解析错误;_Zsh_Oh My Zsh_Zshrc - Fatal编程技术网

“)'附近的zsh函数用例条件解析错误;

“)'附近的zsh函数用例条件解析错误;,zsh,oh-my-zsh,zshrc,Zsh,Oh My Zsh,Zshrc,我在下面的博客中设置了一个zsh函数来切换aws cli配置文件 : 这是博客中的zsh函数: function aws-switch() { case ${1} in "") clear) export AWS_PROFILE="" ;; *) export AWS_PROFILE="${1}" ;; esac } #compdef

我在下面的博客中设置了一个zsh函数来切换aws cli配置文件 :

这是博客中的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:解析错误
我阅读了zsh函数文档,但仍然不太善于理解语法,以及如何解决这个问题

查看zsh手册页(
man zshmisc
):

[(]模式[|模式]…)列表(;|;&| |)中的大小写单词。。。以撒

如您所见,您必须通过
|
来分离多个图案:

case $1 in
  |clear)
    ....

对于类似C的故障,还可以使用
“”):&
,执行no op
并用
终止案例&
,这会导致执行下一个块,如果它与
$1
匹配,也会执行下一个块?我试着在你的建议和许多其他的立场中加入clear like,但没有一个有效。发布你完整的修改代码。它应该会起作用。我用我的Zsh 5.5.1版进行了试用。