Search code examples
google-cloud-platformzshgcloud

cloud zsh `=` notation vs. string notation


Why does this work gcloud config list project --format 'value(core.project)' but not this gcloud config list project --format=value(core.project)? The documentation uses the = notation. I get the error number expected when using it. My guess is that it's trying to evaluate the projection value(core.project) as a number and the `` tells it to evaluate as a string.


Solution

  • I'm unfamiliar with zsh but the bash returns a syntax error unrecognized token '(' if you do this.

    This is not an issue with gcloud per se.

    The issue is that zsh (and bash) shells have their own interpretation of (...). In bash, this is the command for a subshell.

    The solution is to ensure that the flag values are passed to the command as-is rather than be evaluated by the shell.

    As @hobbs points out correctly, you can use '...' or "..." to wrap the flag value correctly without issue. My preference is --flag=value and, when using bash, '...' when no variable expansion is ever desired and "..." when it is.

    My personal preference is to always use = and default to "..."

    gcloud config list project \
    --format="value(core.project)"